s365b.core.zipstream

Write a ZIP archive as a stream, for downloads of many files.

The archive is produced while it is sent: nothing is held in memory but the piece being written, so a download of thousands of messages starts at once. Python’s zipfile writes to a stream it cannot seek by putting each file’s sizes after its data (ZIP64 where needed).

Attributes

Functions

zip_stream(files, when) → collections.abc.AsyncIterator[bytes]

Yield a ZIP archive of files, compressed, as it is written.

Module Contents

s365b.core.zipstream.CHUNK = 1048576[source]
async s365b.core.zipstream.zip_stream(files: collections.abc.Iterable[s365b.modules.sdk.ExportFile], when: datetime.datetime) → collections.abc.AsyncIterator[bytes][source]

Yield a ZIP archive of files, compressed, as it is written.

Parameters:
  • files – The files; their paths use / between folders.

  • when – Modification time recorded for every file.

Yields:

Pieces of the archive.