CompressionsHelper Module

Utilities for extracting and handling compressed archive formats.

class HMB.CompressionsHelper.CompressionsHelper[source]

Bases: object

Convenience wrappers to extract various archive formats. This class provides methods to extract common archive formats such as .tar, .zip, .7z, and .rar. It uses the standard library for .tar and .zip files, and optional third-party libraries for .7z and .rar files. If the required third-party library is not installed, an ImportError will be raised.

ExtractFileUsingTarfile(path, destination)[source]

Extract a tar/ tar.gz / tar.bz2 archive using the standard library tarfile.

Parameters:
  • path (str) – Path to the archive file.

  • destination (str) – Directory to extract files into. Will be created if missing.

ExtractFileUsingZipfile(path, destination)[source]

Extract a ZIP archive using the standard library zipfile.

Parameters:
  • path (str) – Path to the .zip file.

  • destination (str) – Directory to extract files into. Will be created if missing.

ExtractFileUsing7zfile(path, destination)[source]

Extract a 7-zip (.7z) archive using the optional py7zr package. If py7zr is not installed an ImportError will be raised.

Parameters:
  • path (str) – Path to the .7z file.

  • destination (str) – Directory to extract files into. Will be created if missing.

ExtractFileUsingRarfile(path, destination)[source]

Extract a RAR archive using the optional rarfile package. If rarfile is not installed an ImportError will be raised.

Parameters:
  • path (str) – Path to the .rar file.

  • destination (str) – Directory to extract files into. Will be created if missing.

ExtractFileUsingUnrar(path, destination)[source]

Extract a RAR archive using the optional unrar package (alternate to rarfile). If unrar is not installed an ImportError will be raised.

Parameters:
  • path (str) – Path to the .rar file.

  • destination (str) – Directory to extract files into. Will be created if missing.

ExtractFileUsingUnzip(path, destination)[source]

Extract an archive with a third-party unzip package if available. This is provided for environments that prefer a non-stdlib unzip utility. If the unzip package is not installed an ImportError will be raised.

Parameters:
  • path (str) – Path to the archive file.

  • destination (str) – Directory to extract files into. Will be created if missing.