From 5ef746ab9ec5b139d82b0de764d3d43b5c865ca2 Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Tue, 25 Jul 2017 17:18:40 +0300 Subject: [PATCH] Allow to specify a place where to unpack zip data Now unpack_zip_archive_in_memory always unpacks data in folder called 'content'. To add more flexibility we add new parameter that defines where to unpack the data. Change-Id: Ieb2f24776293a1890d755cddc458511b16f8eb82 --- glare/objects/meta/file_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/glare/objects/meta/file_utils.py b/glare/objects/meta/file_utils.py index 680c1a2..93d0276 100644 --- a/glare/objects/meta/file_utils.py +++ b/glare/objects/meta/file_utils.py @@ -102,12 +102,13 @@ def upload_content_file(context, af, data, blob_dict, key_name, af.update_blob(context, af.id, blob_dict, getattr(af, blob_dict)) -def unpack_zip_archive_in_memory(context, af, fd): - """Unpack zip archive in memory. +def unpack_zip_archive_in_memory(context, af, field_name, fd): + """Unpack zip archive in memory and write its content to artifact folder. :param context: user context :param af: artifact object - :param fd: file + :param field_name: blob dict name where to unpack the data + :param fd: zip archive :return io.BytesIO object - simple stream of in-memory bytes, None """ flobj = io.BytesIO(fd.read()) @@ -122,6 +123,6 @@ def unpack_zip_archive_in_memory(context, af, fd): if not name.endswith('/'): upload_content_file( context, af, utils.BlobIterator(zip_ref.read(name)), - 'content', name) + field_name, name) flobj.seek(0) return flobj, None