I have a list of very large objects objects, that I want to compress and save to the hard drive.
My current approach is
import brotli
import dill
# serialize list of objects
objects_serialized = dill.dumps(objects, pickle.HIGHEST_PROTOCOL)
# compress serialized string
objects_serialized_compressed = brotli.compress(data=objects_serialized, quality=1)
# write compressed string to file
output.write(objects_serialized_compressed)
However, if objects is very large, this leads to a memory error, since -- for some time -- I simultaneously carry objects, objects_serialized, objects_serialized_compressed around in their entirety.
Is there a way to do this chunk-wise? Presumably the first step -- serializing the objects -- has to done in one go, but perhaps the compression and writing to file can be done chunk-wise?
I'd try this, after many attemps:
This requires
brotli 1.0.9, as provided bypip-- it does not work withbrotlipy, as provided by anaconda.