packio
Public methods and classes for packio package.
Submodules
Classes
Context manager to read multiple objects from the same file. |
|
Context manager to write multiple objects to the same file. |
Functions
|
Unzip an archive into a destination directory. |
|
Unzip a file into a destination directory. |
|
Zip a directory to create an archive. |
|
Zip files into a single archive with no directory structure. |
Package Contents
- class packio.Reader(path: pathlib.Path)[source]
Context manager to read multiple objects from the same file.
Initialize zipfile with a file path.
- class packio.Writer(path: pathlib.Path)[source]
Context manager to write multiple objects to the same file.
Initialize the reader with a file path.
- __enter__() ArchiveWriter[source]
Create temporary directory and zip object, return callable.
- packio.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.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.
- packio.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.