I'm trying to set up a code to pack a few big files (from tens to hundreds of gigabytes) into one archive. The compression methods that supported in tarfile module are a bit slow for such a big amount of data, so I would like to use some external compress module like lz4 to achive better speed of compression. Unfortunately I can't find a way how to create tar file and compress it with lz4 on the fly to avoid creating temporary tar file. The documentation of tarfile module says that there's a way to open an uncompressed stream for writing using 'w|' mode. Is it the way to stream tar file directly to lz4 module? If so, what's the proper way to use it? Thank you very much.
Python: how to create tar file and compress it on the fly with external module, using different compression methods not available in tarfile module?
2.4k views Asked by Trevor_Numbers At
2
There are 2 answers
0
Cyan
On
You can pipe the result of the tar command directly to the lz4 utility. This will avoid usage of any intermediate file. Here is an example (assuming you have both tar and lz4 installed on your system) :
tar cvf - * | lz4 > mypack.tar.lz4
The - here tells to output the result from tar to stdout. Of course, you can change the * with whichever target you want to tar.
The reverse operation is also possible :
lz4 -d mypack.tar.lz4 | tar xv
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in COMPRESSION
- Should I compress images in java backend before sending to frontend?
- saving always adds artefacts to my images that photoshop doesn't
- Kafka compression on Broker side
- I am trying to compress video in Android using ffmpeg
- Compress gzip/Deflate string with golang
- how to convert different length of bits into byte array?
- knowledge distillation in a multistep model
- How to decompress the contents of a var to another var?
- Why response body not compressed when use webtestclient?
- How to monkey-patch np.savez_compressed to add compression level, without editing numpy's source files?
- incorrect header check while implementing GZIP in spring boot REST APIs
- Create algorhitm to create .pak file from unpack code
- Problem with decompressing algorithm in firefox (works in chrome/edge)
- Can I ignore some keyword while compressing css file through webpack? In other words I need a loader which just compress my file without validation
- PNG cropping increases file size
Related Questions in TAR
- Differential backup for delete and restoring files and folders
- .ova file to run in a Docker container
- tar extract zip archive from file or STDIN - discrepancy
- How can I write a streaming tar file from a generator?
- Excluding files from top level directory when extracting tar archives
- Tar: Cannot stat: No such file or directory
- Error installing package in Octave Portable on Windows 10
- I received a 'no space left on device' error during the untarring process, even though I have enough space and sufficient inodes
- Dynamic tar/archive creation in Mojolicious
- yarn install starts failing randomly with tar content of undefined failed
- libarchive error code -30 opening a tarball: Unrecognized archive format
- Is there a library in React Native for compressing to tar and then zipping with gzip to create a tar.gz?
- Extract specific folders from tar.gz archive
- Create tar from multiple folders and change folder name
- Why reading a compressed TAR file in reverse order is 100x slower?
Related Questions in TARFILE
- Decompressing large streams with Python tarfile
- Is there any way to read data from tar.gz files online without downloading them locally?
- tar: Removing leading `/' from member names showing in tarfile.add (python)
- Reading the content inside the directories and files of the .tar.gz archive without extracting it with tarfile lib
- TarFile.extractall base path wrong, python?
- TarFile.extractfile() as context manager raises 'AttributeError: __enter__'
- Python Renaming tar file contents without extracting
- "tarfile.ReadError: file could not be opened successfully" when loading a model in Streamlit app
- "ReadError: file could not be opened successfully" when opening '.tgz' with tarfile
- Why does it sometimes look like Python tarfile is extracting a directory with its contents?
- Get tar file buffer without write to file with Python
- High memory usage Lambda function (AWS) using Python tarfile Lib
- Unable to pull Tar files from Jfrog Artifactory when file size is over 7gb
- Download and extract .tar files with multiprocessing
- Untar gzip to different directories
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Per our conversation above.
From there you can do the usual
tar.addfile. FYI: as I stated in the conversation. GNU tar can auto detect gz and bz2 but not lz4. Just a note. So you have to dolz4 -c -d stdin.lz4 | tar xf -to extract files. If you simply didtar xfit would fail.