gws.lib.zipx

Zipfile wrappers.

Source code: gws.lib.zipx

Package Contents

exception gws.lib.zipx.Error

Bases: gws.Error

GWS error.

gws.lib.zipx.zip(path: str, *sources: str, flat: bool = False) int

Create a zip archive in a file.

Parameters:
  • path – Path to the zip archive.

  • sources – Paths to the sources to zip.

  • flat – If True base names are being kept in zip archive, else whole paths are being kept in zip archive. Default is False

Returns:

The amount of files in the zip archive.

gws.lib.zipx.zip_to_bytes(*sources: str, flat: bool = False) bytes

Create a zip archive in memory.

Parameters:
  • sources – Paths to the sources to zip.

  • flat – If True only base names will be returned, else the whole paths will be returned. Default is False.

Returns:

The names of the file paths encoded in bytes.

gws.lib.zipx.unzip(path: str, target_dir: str, flat: bool = False) int

Unpack a zip archive into a directory.

Parameters:
  • path – Path to the zip archive.

  • target_dir – Path to the target directory.

  • flat – If True omit path and consider only base name of files in the zip archive, else complete paths are considered of files in the zip archive. Default is False.

Returns:

The amount of unzipped files.

gws.lib.zipx.unzip_bytes(source: bytes, target_dir: str, flat: bool = False) int

Unpack a zip archive in memory into a directory.

Parameters:
  • source – Path to the zip archive.

  • target_dir – Path to the target directory.

  • flat – If True omit path and consider only base name of files in the zip archive, else complete paths are considered of files in the zip archive. Default is False.

Returns:

The amount of unzipped files.

gws.lib.zipx.unzip_to_dict(path: str, flat: bool = False) dict

Unpack a zip archive into a dict.

Parameters:
  • path – Path to the zip archive.

  • flat – If True then the dictionary contains the base names of the unzipped files, else it contains the whole path. Default is False.

Returns:

A dictionary containing all the file paths or base names.

gws.lib.zipx.unzip_bytes_to_dict(source: bytes, flat: bool = False) dict

Unpack a zip archive in memory into a dict.

Parameters:
  • source – Path to zip archive.

  • flat – If True then the dictionary contains the base names of the unzipped files, else it contains the whole path. Default is False.

Returns:

A dictionary containing all the file paths or base names.