diff --git a/antarest/study/storage/study_download_utils.py b/antarest/study/storage/study_download_utils.py index bae6458e3b..d73d21350a 100644 --- a/antarest/study/storage/study_download_utils.py +++ b/antarest/study/storage/study_download_utils.py @@ -361,23 +361,23 @@ def write_inside_archive(path: Path, file_type: ExportFormat, matrix: MatrixAggr f.writestr(f"{ts_data.name}.csv", bytes_to_writes) else: - with tarfile.open(path, mode="w:gz") as f: - for ts_data in matrix.data: - bytes_to_writes = StudyDownloader.create_csv_file(ts_data, matrix) - file_count += 1 - total_size += len(bytes_to_writes) - if total_size > max_size: - raise ValueError("L'archive dépasse la taille maximale autorisée.") - if file_count > max_files: - raise ValueError("L'archive contient trop de fichiers.") - - data_file = BytesIO(bytes_to_writes) - data_file.seek(0, os.SEEK_END) - file_size = data_file.tell() - data_file.seek(0) - info = tarfile.TarInfo(name=f"{ts_data.name}.csv") - info.size = file_size - f.addfile(tarinfo=info, fileobj=data_file) + f= tarfile.open(path, mode="w:gz") + for ts_data in matrix.data: + bytes_to_writes = StudyDownloader.create_csv_file(ts_data, matrix) + file_count += 1 + total_size += len(bytes_to_writes) + if total_size > max_size: + raise ValueError("L'archive dépasse la taille maximale autorisée.") + if file_count > max_files: + raise ValueError("L'archive contient trop de fichiers.") + + data_file = BytesIO(bytes_to_writes) + data_file.seek(0, os.SEEK_END) + file_size = data_file.tell() + data_file.seek(0) + info = tarfile.TarInfo(name=f"{ts_data.name}.csv") + info.size = file_size + f.addfile(tarinfo=info, fileobj=data_file) @staticmethod def create_csv_file(ts_data: TimeSeriesData, matrix: MatrixAggregationResultDTO) -> bytes: