Read and write ZIP files.
MicroPython implementation ported from CPython 3.12 https://raw.githubusercontent.com/python/cpython/3.12/Lib/zipfile/__init__.py
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
From https://github.com/jonnor/micropython-zipfile/blob/master/zipfile.py
Usage:
# Import the module from zipfile import ZipFile, ZIP_DEFLATED, ZIP_STORED
# Create a .zip archive # for compression, swap ZIP_STORED with ZIP_DEFLATED path = 'myarchive.zip' with ZipFile(path, 'w', ZIP_STORED) as archive:
contents = b'Hello World Hello World Hello World
- '
- with archive.open('test.txt', 'w') as f:
- f.write(contents)
# List the information from a .zip archive print(' Listing information') with ZipFile(path, 'r') as archive:
- for info in archive.infolist():
- print(info.filename) print(' System: ' + str(info.create_system) + '(0 = Windows, 3 = Unix)') print(' ZIP version: ' + str(info.create_version)) print(' Compressed: ' + str(info.compress_size) + ' bytes') print(' Uncompressed: ' + str(info.file_size) + ' bytes')
# Read a file from inside .zip archive print(' Reading file') with ZipFile(path) as myzip:
- with myzip.open('test.txt') as myfile:
- print(myfile.read())
| Class | |
Undocumented |
| Class | |
Undocumented |
| Class | |
File-like object for reading an archive member. Is returned by ZipFile.open(). |
| Class | |
Class with methods to open, read, write, close, list zip files. |
| Class | |
Class with attributes describing each file in the ZIP archive. |
| Exception | |
Undocumented |
| Exception | |
Raised when writing a zipfile, the zipfile requires ZIP64 extensions and those extensions are disabled. |
| Exception | |
Undocumented |
| Function | is |
Quickly see if a file is a ZIP file by checking the magic number. |
| Function | warn |
Undocumented |
| Constant | ALTSEP |
Undocumented |
| Constant | BZIP2 |
Undocumented |
| Constant | CURDIR |
Undocumented |
| Constant | DEFAULT |
Undocumented |
| Constant | LZMA |
Undocumented |
| Constant | MAX |
Undocumented |
| Constant | OS |
Undocumented |
| Constant | PARDIR |
Undocumented |
| Constant | SEEK |
Undocumented |
| Constant | SEEK |
Undocumented |
| Constant | SEEK |
Undocumented |
| Constant | ZIP64 |
Undocumented |
| Constant | ZIP64 |
Undocumented |
| Constant | ZIP |
Undocumented |
| Constant | ZIP |
Undocumented |
| Constant | ZIP |
Undocumented |
| Constant | ZIP |
Undocumented |
| Constant | ZIP |
Undocumented |
| Constant | ZIP |
Undocumented |
| Variable | compressor |
Undocumented |
| Variable | is |
Undocumented |
| Variable | size |
Undocumented |
| Variable | size |
Undocumented |
| Variable | size |
Undocumented |
| Variable | size |
Undocumented |
| Variable | size |
Undocumented |
| Variable | string |
Undocumented |
| Variable | string |
Undocumented |
| Variable | string |
Undocumented |
| Variable | string |
Undocumented |
| Variable | string |
Undocumented |
| Variable | struct |
Undocumented |
| Variable | struct |
Undocumented |
| Variable | struct |
Undocumented |
| Variable | struct |
Undocumented |
| Variable | struct |
Undocumented |
| Class | _ |
Undocumented |
| Class | _ |
Undocumented |
| Class | _ |
Undocumented |
| Function | _check |
Undocumented |
| Function | _check |
Undocumented |
| Function | _ |
Return data from the "End of Central Directory" record, or None. |
| Function | _ |
Read the ZIP64 end-of-archive records and use that to update endrec |
| Function | _gen |
Undocumented |
| Function | _get |
Undocumented |
| Function | _get |
Undocumented |
| Function | _path |
Undocumented |
| Function | _path |
Undocumented |
| Function | _path |
Undocumented |
| Function | _path |
Undocumented |
| Function | _path |
Undocumented |
| Function | _sanitize |
Terminate the file name at the first null byte and ensure paths always use forward slashes as the directory separator. |
| Function | _strip |
Undocumented |
| Function | _ |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD64 |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _CD |
Undocumented |
| Constant | _DD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _ECD |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _FH |
Undocumented |
| Constant | _MASK |
Undocumented |
| Constant | _MASK |
Undocumented |
| Constant | _MASK |
Undocumented |
| Constant | _MASK |
Undocumented |
| Constant | _MASK |
Undocumented |
| Constant | _MASK |
Undocumented |
| Variable | _crctable |
Undocumented |
| Variable | _stat |
Undocumented |
Quickly see if a file is a ZIP file by checking the magic number.
The filename argument may be a file or file-like object too.
Return data from the "End of Central Directory" record, or None.
The data is a list of the nine items in the ZIP "End of central dir" record followed by a tenth item, the file seek offset of this record.