Package: jk-packunpack
jk_packunpackIntroductionHelper module to create or unpack tar archives, compress or uncompress files.Information about this module can be found here:github.orgpypi.python.orgWhy 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 noteATTENTION:The API of this module has been changed with the release0.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 classesPacker1andUnpacker1instead ofPackerandUnpacker.If you want to use the more advanced API modify your calls to methods inPackerandUnpacker. This is a simple step as the new implementations are very similar, you just need to invoke them with named arguments.Limitations of this moduleThis module supports the following compression algorithms only:gzipbzip2xzThis compression/uncompression is performed using the standard implementations provided by Python.Packing and unpacking oftarfiles is supported as well, but only on POSIX operating systems. The reason for this is that
internally thetarprogram is invoked directly, which is not available on non-POSIX operating systems.How to use this moduleImport this modulePlease include this module into your application using the following code:importjk_packunpackFor logging import thejk_loggingmodule:importjk_loggingCompress a fileThe following example demonstrates how to compress a file withgzip:inputFilePath="myinputfile.txt"compression="gzip"chmodValue=0o700withjk_logging.ConsoleLogger.create()aslog:resultInfo=jk_packunpack.Packer.compressFile(filePath=inputFilePath,compression=compression,chModValue=chmodValue,log=log)print(resultInfo.toFilePath)ForchmodValueyou can specify a string such as "rw-rw----" or an instance ofjk_utils.ChModValueas well.For compression you can specify any of these values:gz,gzip,bz2,bzip2,xz.Uncompress a fileThe following example demonstrates how to uncompress a file:inputFilePath="myinputfile.txt.gz"chmodValue=0o700withjk_logging.ConsoleLogger.create()aslog:resultFilePath=jk_packunpack.Unpacker.uncompressFile(filePath=inputFilePath,bDeleteOriginal=True,chModValue=chmodValue,log=log)print(resultFilePath)ForchmodValueyou can specify a string such as "rw-rw----" or an instance ofjk_utils.ChModValueas well.Uncompressing will automatically detect the compression format used by inspecting the file extension.Pack a directoryThe following example demonstrates how to pack the contents of a directory usingtar:inputDirPath="./my/example/dir"outputTarFilePath="./my/example-dir.tar"chmodValue=0o700withjk_logging.ConsoleLogger.create()aslog:jk_packunpack.Packer.tarDirContents(srcDirPath=inputDirPath,destTarFilePath=outputTarFilePath,chModValue=chmodValue,log=log)ForchmodValueyou can specify a string such as "rw-rw----" or an instance ofjk_utils.ChModValueas well.Unpack a directoryThe following example demonstrates how to unpack atarfile to a directory:inputTarFilePath="./my/example-dir.tar"outputDirPath="./my/new/dir"withjk_logging.ConsoleLogger.create()aslog:jk_packunpack.Unpacker.untarToDir(srcTarFilePath=inputTarFilePath,destDirPath=outputDirPath,log=log)Contact InformationThis 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:Jürgen Knauth:pubsrc@binary-overflow.deLicenseThis software is provided under the following license:Apache Software License 2.0