packio.zipping
Tools to simplify zipping and unzipping of files.
Attributes
Functions
|
Zip files into a single archive with no directory structure. |
|
Zip a directory to create an archive. |
|
Unzip an archive into a destination directory. |
|
Unzip a file into a destination directory. |
Module Contents
- packio.zipping.zipflat(*, files: list[PathType], outfile: PathType) None[source]
Zip files into a single archive with no directory structure.
- Parameters:
files – List of files to zip.
outfile – Path to the resulting zip archive.
- Raises:
ValueError – If the names of the provided files are not unique.
- packio.zipping.zip(directory: PathType, *, outfile: PathType, format: str = 'zip') None[source]
Zip a directory to create an archive.
This preserves the directory structure within the zip file. Implemented as a thin wrapper around shutil.make_archive.
- Parameters:
directory – Directory containing files to zip.
outfile – Full path to the resulting zip archive, including any extension. Users may choose not to add an extension (overriding the behavior of shutil.make_archive, which adds an extension).
format – Format of the archive, default is ‘zip’. Other formats like ‘tar’, ‘gztar’, etc. can be used.
- packio.zipping.unzip(*, file: PathType, dest_dir: PathType) None[source]
Unzip an archive into a destination directory.
- Parameters:
file – Path to the zip archive.
dest_dir – Directory to unzip the archive into.
- packio.zipping.unzipflat(*, file: PathType, dest_dir: PathType, overwrite: bool = False) None[source]
Unzip a file into a destination directory.
- Parameters:
file – Path to the zip archive.
dest_dir – An existing directory to unzip the archive into.
overwrite – If True, overwrite any existing files in the destination directory.
- Raises:
ValueError – If the input file is not a zip archive.
ValueError – If any contents of the input zip archive are directories – expect a flat archive.
FileExistsError – If any files in the archive would overwrite existing files in the destination directory.