Skip to main content

jk_packunpack

Introduction

Helper module to create or unpack tar archives, compress or uncompress files.

Information about this module can be found here:

Why this module?

For a wide variety of applications it would be very convenient to have a simple API for packing/unpacking tar files and for compressing/uncompressing files with standard algorithms. This is the reason why this module has been created: To simplify such tasks.

Important note

ATTENTION: The API of this module has been changed with the release 0.2022.2.6.

The reasons for this quite uncommon modification:

  • The author was able to improve the API and it does not make much sense to continue with an API of lower quality.
  • To the knowledge of the author this module does not have many users anyway.
  • An upgrade to the new API is simple.

Upgrading is very simple. For this you have two possibilities:

  • If you want to continue using the old API please refer to classes Packer1 and Unpacker1 instead of Packer and Unpacker.
  • If you want to use the more advanced API modify your calls to methods in Packer and Unpacker. This is a simple step as the new implementations are very similar, you just need to invoke them with named arguments.

Limitations of this module

This module supports the following compression algorithms only:

  • gzip
  • bzip2
  • xz This compression/uncompression is performed using the standard implementations provided by Python.

Packing and unpacking of tar files is supported as well, but only on POSIX operating systems. The reason for this is that internally the tar program is invoked directly, which is not available on non-POSIX operating systems.

How to use this module

Import this module

Please include this module into your application using the following code:

import jk_packunpack

For logging import the jk_logging module:

import jk_logging

Compress a file

The following example demonstrates how to compress a file with gzip:

inputFilePath = "myinputfile.txt"
compression = "gzip"
chmodValue = 0o700

with jk_logging.ConsoleLogger.create() as log:

	resultInfo = jk_packunpack.Packer.compressFile(
		filePath=inputFilePath,
		compression=compression,
		chModValue=chmodValue,
		log=log)

	print(resultInfo.toFilePath)

For chmodValue you can specify a string such as "rw-rw----" or an instance of jk_utils.ChModValue as well.

For compression you can specify any of these values: gz, gzip, bz2, bzip2, xz.

Uncompress a file

The following example demonstrates how to uncompress a file:

inputFilePath = "myinputfile.txt.gz"
chmodValue = 0o700

with jk_logging.ConsoleLogger.create() as log:

	resultFilePath = jk_packunpack.Unpacker.uncompressFile(
		filePath=inputFilePath,
		bDeleteOriginal=True,
		chModValue=chmodValue,
		log=log)

	print(resultFilePath)

For chmodValue you can specify a string such as "rw-rw----" or an instance of jk_utils.ChModValue as well.

Uncompressing will automatically detect the compression format used by inspecting the file extension.

Pack a directory

The following example demonstrates how to pack the contents of a directory using tar:

inputDirPath = "./my/example/dir"
outputTarFilePath = "./my/example-dir.tar"
chmodValue = 0o700

with jk_logging.ConsoleLogger.create() as log:

	jk_packunpack.Packer.tarDirContents(
		srcDirPath=inputDirPath,
		destTarFilePath=outputTarFilePath,
		chModValue=chmodValue,
		log=log)

For chmodValue you can specify a string such as "rw-rw----" or an instance of jk_utils.ChModValue as well.

Unpack a directory

The following example demonstrates how to unpack a tar file to a directory:

inputTarFilePath = "./my/example-dir.tar"
outputDirPath = "./my/new/dir"

with jk_logging.ConsoleLogger.create() as log:

	jk_packunpack.Unpacker.untarToDir(
		srcTarFilePath=inputTarFilePath,
		destDirPath=outputDirPath,
		log=log)

Contact Information

This work is Open Source. This enables you to use this work for free.

Please have in mind this also enables you to contribute. We, the subspecies of software developers, can create great things. But the more collaborate, the more fantastic these things can become. Therefore Feel free to contact the author(s) listed below, either for giving feedback, providing comments, hints, indicate possible collaborations, ideas, improvements. Or maybe for "only" reporting some bugs:

License

This software is provided under the following license:

  • Apache Software License 2.0

Metadata

Release files for jk-packunpack 0.2022.10.25

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jk-packunpack 0.2022.10.25
File Size Uploaded
jk_packunpack-0.2022.10.25.tar.gz 14.8 kB Details

Release files / jk_packunpack-0.2022.10.25.tar.gz

Download URL jk_packunpack-0.2022.10.25.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
860a4134e9780ad5607869ed005aa4da1ea2bda2d67f1d796b2962aa3dc8e20b
BLAKE2b-256 checksum
How to use checksums
3812c9e45dc3fbbe8de82f932e652aad91d999f31e94c76ad1797e3f67df1cec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.10
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page