From 2f8698769606d3643c2e06ed6894fdf772c032fe Mon Sep 17 00:00:00 2001 From: "shimoda.m@nds-tyo.co.jp" Date: Tue, 1 Aug 2023 16:39:12 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20gzip=E3=81=8C=E3=81=86=E3=81=BE=E3=81=8F?= =?UTF-8?q?=E8=A7=A3=E5=87=8D=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E5=95=8F?= =?UTF-8?q?=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ecs/jskult-batch-daily/src/aws/s3.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ecs/jskult-batch-daily/src/aws/s3.py b/ecs/jskult-batch-daily/src/aws/s3.py index a4ebc30a..3a5fe240 100644 --- a/ecs/jskult-batch-daily/src/aws/s3.py +++ b/ecs/jskult-batch-daily/src/aws/s3.py @@ -1,6 +1,7 @@ +import gzip import os import os.path as path -import tarfile +import shutil import tempfile import boto3 @@ -134,14 +135,14 @@ class VjskReceiveBucket(S3Bucket): return temporary_file_path def unzip_data_file(self, filename: str): - ret = [] - with tarfile.open(filename) as tar: - temp_dir = os.path.dirname(filename) - tar.extractall(path=temp_dir) - extracted_files = tar.getnames() - for extracted_file in extracted_files: - file = os.path.join(temp_dir, extracted_file) - ret.append(file) + temp_dir = os.path.dirname(filename) + decompress_filename = os.path.basename(filename).replace('.gz', '') + decompress_file_path = os.path.join(temp_dir, decompress_filename) + with gzip.open(filename, 'rb') as gz: + with open(decompress_file_path, 'wb') as decompressed_file: + shutil.copyfileobj(gz, decompressed_file) + + ret = [decompress_file_path] return ret def backup_dat_file(self, target_files: list, datetime_key: str):