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):