ZipFile#

class caf.cvt.data_cleaning.ZipFile(file, mode='r', compression=0, allowZip64=True, compresslevel=None, *, strict_timestamps=True, metadata_encoding=None)#

Bases: object

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.

Attributes

comment

The comment text associated with the ZIP file.

fp

Methods

__init__(file[, mode, compression, ...])

Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.

close()

Close the file, and for mode 'w', 'x' and 'a' write the ending records.

extract(member[, path, pwd])

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'.

extractall([path, members, 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().

getinfo(name)

Return the instance of ZipInfo given 'name'.

infolist()

Return a list of class ZipInfo instances for files in the archive.

mkdir(zinfo_or_directory_name[, mode])

Creates a directory inside the zip archive.

namelist()

Return a list of file names in the archive.

open(name[, mode, pwd, force_zip64])

Return file-like object for 'name'.

printdir([file])

Print a table of contents for the zip file.

read(name[, pwd])

Return file bytes for name.

setpassword(pwd)

Set default password for encrypted files.

testzip()

Read all the files and check the CRC.

write(filename[, arcname, compress_type, ...])

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

writestr(zinfo_or_arcname, data[, ...])

Write a file into the archive.

Attributes Documentation

comment#

The comment text associated with the ZIP file.

fp = None#