I am trying tp Create a directory in memory in python, zip it and return it as bytes.
I have used the following tools:
def some_func(data):
some_large_number = 10000000000000000000000000
f = tempfile.SpooledTemporaryFile(max_size = some_large_number, mode = 'w+b'. dir = 'temp/')
with f as file:
the_directory = data.to_directory()
a = shutil.make_archive(file, 'zip', the_directory)
return pickle.dumps(a)
However, I get the following error message: TypeError: Expected str, bytes, or os.Pathlike object, not spooledTemporaryFile
I have also tries 'return io.BytesIO(a)' and 'io.StringIO(a)' yet get the same error message. Not sure how to return the object in the approptiate type instead of spooledTemporaryFile
?
I also tried the following:
def some_func(data):
some_large_number = 10000000000000000000000000
f = tempfile.SpooledTemporaryFile(max_size = some_large_number, mode = 'w+b'. dir = 'temp/')
with f as file:
the_directory = data.to_directory()
a = shutil.make_archive('final', 'zip', io.BytesIO(the_directory))
return pickle.dumps(a)
and got the following error: TypeError: A bytes-like object is required not zarr_store
Note: the_director
is a Zarr_store type object but I thought calling io.BytesIO()
converts that to bytes?