Sujet précédent

5.17. utils — Utilities

Sujet suivant

5.17.2. importing — Importing helpers

Cette page

Autres langues

5.17.1. archive — Module to stream tar and zip archives

plmapp.utils.archive.get_available_name(name, exiting_files)[source]
plmapp.utils.archive.ZIP_AUTO = -1

True if files are compressed or not according to their extension

plmapp.utils.archive.STORED_FORMATS = set(['pptx', 'mpg', 'tgz', 'ods', 'odt', 'gz', 'jpg', 'xz', 'rar', 'odm', 'odf', 'odg', 'mpeg', 'bz2', 'zip', 'mkv', 'm4p', 'wmv', 'gif', 'ra', 'rm', 'odp', 'm4a', 'svgz', 'xlsx', 'docx', 'ram', 'mpa', '3gp', 'dotx', 'mov', 'dat', 'xlsm', 'jpeg', 'flac', 'docm', 'otp', 'ogg', 'ott', 'png', 'aaf', 'aac', 'ace', 'avi', '.zipx', 'flv', 'mp2', 'mp3', 'pptm'])

formats that are stored uncompressed

class plmapp.utils.archive.IterZipFile(compression=-1, allowZip64=False)[source]

A write-only ZipFile that does not write to a file but yields its output.

Example:

z = IterZipFile()
for buf in z.write(filename, arcname):
    # do stuff with buf
for buf in z.close():
    # do stuff with buf

The code is mostly based on zipfile.ZipFile.

Paramètres:
  • compression – ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib) or ZIP_AUTO (compression or not according to the filename).
  • allowZip64 – if True ZipFile will create files with ZIP64 extensions when needed, otherwise it will raise an exception when this would be necessary.
write(filename, arcname=None, compress_type=None)[source]

Put the bytes from filename into the archive under the name arcname.

close()[source]

Close the file, and for mode “w” and “a” write the ending records.

plmapp.utils.archive.generate_tarfile(files)[source]

Returns a generator that yields files as a tar file.

This generator does not create temporary files and is designed to not consume too much memory so it can be used to serve efficiently a tar file of large files.

Paramètres:files – a sequence of class:.DocumentFile
plmapp.utils.archive.generate_zipfile(files)[source]

Returns a generator that yields files as a zip file.

This generator does not create temporary files and is designed to not consume too much memory so it can be used to serve efficiently a tar file of large files.

Paramètres:
  • files – a sequence of class:.DocumentFile
  • compressedTrue if files should be compressed (default: True)
plmapp.utils.archive.ARCHIVE_FORMATS = ['tar', 'zip']

List of available archive formats (currently: zip and tar).

plmapp.utils.archive.generate_archive(files, format)[source]