AESZipFile

class AESZipFile(*args, **kwargs)[source]

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

Attributes Summary

comment

The comment text associated with the ZIP file.

fp

Methods Summary

close

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

extract

Extract a member from the archive to the current working directory, using its full name.

extractall

Extract all members from the archive to the current working directory.

get_encrypter

getinfo

Return the instance of ZipInfo given 'name'.

infolist

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

namelist

Return a list of file names in the archive.

open

Return file-like object for 'name'.

printdir

Print a table of contents for the zip file.

read

Return file bytes (as a string) for name.

setencryption

setpassword

Set default password for encrypted files.

testzip

Read all the files and check the CRC.

write

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

writestr

Write a file into the archive.

Methods Documentation

close()

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

extract(member, path=None, pwd=None)

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=None, members=None, pwd=None)

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().

get_encrypter()[source]
getinfo(name)

Return the instance of ZipInfo given ‘name’.

infolist()

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

namelist()

Return a list of file names in the archive.

open(name, mode='r', pwd=None, *, force_zip64=False)

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 encrypt and decrypt files.

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.

printdir(file=None)

Print a table of contents for the zip file.

read(name, pwd=None)

Return file bytes (as a string) for name.

setencryption(encryption, **kwargs)
setpassword(pwd)

Set default password for encrypted files.

testzip()

Read all the files and check the CRC.

write(filename, arcname=None, compress_type=None, compresslevel=None)

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

writestr(zinfo_or_arcname, data, compress_type=None, compresslevel=None)

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.