Class with methods to open, read, write, close, list zip files.
- z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=True,
- compresslevel=None)
- file: Either the path to the file, or a file-like object.
- If it is a path, the file will be opened and closed by ZipFile.
- mode: The mode can be either read 'r', write 'w', exclusive create 'x',
- or append 'a'.
- compression: ZIP_STORED (no compression), ZIP_DEFLATED (requires zlib),
- ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).
- allowZip64: if True ZipFile will create files with ZIP64 extensions when
- needed, otherwise it will raise an exception when this would be necessary.
- compresslevel: None (default for the given compression type) or an integer
- specifying the level to pass to the compressor. When using ZIP_STORED or ZIP_LZMA this keyword has no effect. When using ZIP_DEFLATED integers 0 through 9 are accepted. When using ZIP_BZIP2 integers 1 through 9 are accepted.
| Method | __del__ |
Call the "close()" method in case the user forgot. |
| Method | __enter__ |
Undocumented |
| Method | __exit__ |
Undocumented |
| Method | __init__ |
Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'. |
| Method | __repr__ |
Undocumented |
| Method | close |
Close the file, and for mode 'w', 'x' and 'a' write the ending records. |
| Method | comment |
Undocumented |
| Method | extract |
Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using ... |
| Method | extractall |
Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist()... |
| Method | getinfo |
Return the instance of ZipInfo given 'name'. |
| Method | infolist |
Return a list of class ZipInfo instances for files in the archive. |
| Method | mkdir |
Creates a directory inside the zip archive. |
| Method | namelist |
Return a list of file names in the archive. |
| Method | open |
Return file-like object for 'name'. |
| Method | printdir |
Print a table of contents for the zip file. |
| Method | read |
Return file bytes for name. 'pwd' is the password to decrypt encrypted files. |
| Method | setpassword |
Set default password for encrypted files. |
| Method | testzip |
Read all the files and check the CRC. |
| Method | write |
Put the bytes from filename into the archive under the name arcname. |
| Method | writestr |
Write a file into the archive. The contents is 'data', which may be either a 'str' or a 'bytes' instance; if it is a 'str', it is encoded as UTF-8 first. 'zinfo_or_arcname' is either a ZipInfo instance or the name of the file in the archive. |
| Instance Variable | compression |
Undocumented |
| Instance Variable | compresslevel |
Undocumented |
| Instance Variable | debug |
Undocumented |
| Instance Variable | filelist |
Undocumented |
| Instance Variable | filename |
Undocumented |
| Instance Variable | fp |
Undocumented |
| Instance Variable | metadata |
Undocumented |
| Instance Variable | mode |
Undocumented |
| Instance Variable | |
Undocumented |
| Instance Variable | pwd |
Undocumented |
| Instance Variable | start |
Undocumented |
| Property | comment |
The comment text associated with the ZIP file. |
| Class Method | _sanitize |
Replace bad characters and remove trailing dots from parts. |
| Method | _extract |
Extract the ZipInfo object 'member' to a physical file on the path targetpath. |
| Method | _fpclose |
Undocumented |
| Method | _open |
Undocumented |
| Method | _ |
Read in the table of contents for the ZIP file. |
| Method | _write |
Undocumented |
| Method | _writecheck |
Check for errors before writing a file to the archive. |
| Class Variable | _windows |
Undocumented |
| Instance Variable | _allow |
Undocumented |
| Instance Variable | _comment |
Undocumented |
| Instance Variable | _did |
Undocumented |
| Instance Variable | _file |
Undocumented |
| Instance Variable | _file |
Undocumented |
| Instance Variable | _lock |
Undocumented |
| Instance Variable | _seekable |
Undocumented |
| Instance Variable | _strict |
Undocumented |
| Instance Variable | _writing |
Undocumented |
Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.
Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a ZipInfo object. You can specify a different directory using `path'. You can specify the password to decrypt the file using 'pwd'.
Extract all members from the archive to the current working directory. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by namelist(). You can specify the password to decrypt all files using 'pwd'.
Return file-like object for 'name'.
name is a string for the file name within the ZIP file, or a ZipInfo object.
mode should be 'r' to read a file already in the ZIP file, or 'w' to write to a file newly added to the archive.
pwd is the password to decrypt files (only used for reading).
When writing, if the file size is not known in advance but may exceed 2 GiB, pass force_zip64 to use the ZIP64 format, which can handle large files. If the size is known in advance, it is best to pass a ZipInfo instance for name, with zinfo.file_size set.
Read all the files and check the CRC.
Return None if all files could be read successfully, or the name of the offending file otherwise.
Write a file into the archive. The contents is 'data', which may be either a 'str' or a 'bytes' instance; if it is a 'str', it is encoded as UTF-8 first. 'zinfo_or_arcname' is either a ZipInfo instance or the name of the file in the archive.