Package which allows you to take several file streams and turn them into a single zipfile stream
Project description
StreamZipper
This package allows you to collect several streams of files and then turn several streams into one single zipped stream
This can be usefull if you want to serve multiple files from a file server as a single zip file. but you dont to load all files in memory
installation
pip install stream-zipper
Usage
from stream_zipper import ZipStream
zip_stream = ZipStream()
zip_stream.prepare_stream(file_stream_1)
zip_stream.prepare_stream(file_stream_2)
zip_stream.prepare_stream(file_stream_3)
zipped_stream = zip_stream.stream()
the first argument is always the stream of the file. all other arguments must be passed as keyword argument (key=val)
in the method prepare_stream you can also specify the following kwargs :
- file_name: the name of the file (in the zip)
- zip_info: Can be used to pass a ZipInfo object. (makes other variables useless)
- file_size: size of the file, if set to 0 or not set then it will find the file_length for you
- crc: crc code of the file, if set to 0 or not set then it will find the crc for you
When you provide the crc or file_size it will check the provided value against the data it processed in the stream of that file If these values do not match then an exception will be thrown.
Notes
If you do not know the file_size or crc code then that file will have to be streamed twice to get these variables
if you do know the crc code of the files and you know the file_size then it will only call the stream once
it will check per file if it needs to get these values. so it is possible that only some files/streams have the crc and file_size variables.
from stream_zipper import ZipStream
zip_stream = ZipStream()
zip_stream.prepare_stream(file_stream_1) # no crc or file_size. calls the stream 2 times
zip_stream.prepare_stream(file_stream_2, file_size=100) # no crc calls the stream 2 times
zip_stream.prepare_stream(file_stream_3, crc="CRC-CODE") # no file_size calls the stream 2 times
zip_stream.prepare_stream(file_stream_4, file_size=100, crc="CRC-CODE") # both file_size and crc present will call stream 1 time
zipped_stream = zip_stream.stream() # total streams called 7
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for stream_zipper-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4702aa23043460d111eb260f9dc84c9a2f994c2b4f6baddfe3646be215d4b7c2 |
|
MD5 | f517303f892c3fc27950ef944da6e3fe |
|
BLAKE2b-256 | 20cea9ef93b14e9d0efbe5b973a1e6d4aba77fc9bb38aa30e68b70e4829ab73f |