How to stream from ZipFile? How to zip “on the fly”?

后端 未结 1 397
独厮守ぢ
独厮守ぢ 2021-01-22 02:52

I want to zip a stream and stream out the result. I\'m doing it using AWS Lambda which matters in sense of available disk space and other restrictions. I\'m going to use the zip

相关标签:
1条回答
  • 2021-01-22 03:22

    You might like to try the zipstream version of zipfile. For example, to compress stdin to stdout as a zip file holding the data as a file named TheLogFile using iterators:

    #!/usr/bin/python3
    import sys, zipstream
    with zipstream.ZipFile(mode='w', compression=zipstream.ZIP_DEFLATED) as z:
        z.write_iter('TheLogFile', sys.stdin.buffer)
        for chunk in z:
            sys.stdout.buffer.write(chunk)
    
    0 讨论(0)
提交回复
热议问题