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 best solutions below
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
- new thread blocks main thread
- Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID
- Display images on Django Template Site
- Difference between list() and dict() with generators
- How can I serialize a numpy array while preserving matrix dimensions?
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Why is my program adding int as string (4+7 = 47)?
- store numpy array in mysql
- how to omit the less frequent words from a dictionary in python?
- Update a text file with ( new words+ \n ) after the words is appended into a list
- python how to write list of lists to file
- Removing URL features from tokens in NLTK
- Optimizing for Social Leaderboards
- Python : Get size of string in bytes
- What is the code of the sorted function?
Related Questions in COMPRESSION
- How to use deflate/inflate SetDictionary with raw deflate/inflate?
- C# How to get file/ copy file from a bzip2 (.bz2) file without extracting the file
- How can I compress four floats into a string?
- Create ZIP File Then Send to Client
- compress json data from rest node.js use express compression
- Advanced Data Compression
- Tools to minify CDD and JS files
- How to use multiple threads for zlib compression (same input source)
- Data compression in RDBMS like Oracle, MySQL etc
- Haskell - Lempel-Ziv 78 Compression - very slow, why?
- Python: how to create tar file and compress it on the fly with external module, using different compression methods not available in tarfile module?
- Why isn't lossless compression automatic on computers?
- PHP Image Compression Before Upload
- Compression of char size integer by removing leading zeroes
- BMP Image Compression and Decompression in java
Related Questions in TAR
- Go through tar archive in memory to extract metadata?
- Create a .tar file from a array in PHP
- Extract file from remote ssh host
- What is the best way to compare tar archives in junit testing
- Python: how to create tar file and compress it on the fly with external module, using different compression methods not available in tarfile module?
- Linux shell tar zcvf bad written broke a folder in my server
- Tar backup error
- Node.js - Browserify: Error on parsing tar file
- I want to create a script for unzip (.tar.gz) file via (Python)
- How can I debug the Bourne Shell with gdb?
- How do I delete a single file from a tar.gz archive
- why does this tar command fail when passed as string in ssh call?
- Compress .tar.gz without directories in Perl script
- any difference between "tar cf xxxx | gzip -n" versus "tar zcf xxxx"?
- How can I extract a file from a tar archive without creating the subdirectories?
Related Questions in TARFILE
- Python: how to create tar file and compress it on the fly with external module, using different compression methods not available in tarfile module?
- Getting a single file from a tar file using the tarfile lib in python
- how to automate zipping of files from sql
- python tarfile error: struct.error: unpack requires a string argument of length 4
- In python, if extract a tar.gz file, how to get or set the name of the result file
- Read Contents Tarfile into Python - "seeking backwards is not allowed"
- Read contents of .tar.gz file from website into a python 3.x object
- Add .readinto(b) method to tarfile's ExFileObject?
- How can I create filename.TAR.GZ (ext. In upper case only) using Python tarfile package
- python tarfile created an extra @PaxHeader file and cause error Cannot utime: Operation not permitted
- How to avoid tarfile so that Images should NOT retain the path
- High memory usage with Pythons native tarfile lib
- Where can I store extracted program files from a Python package?
- Python tarfile error - gzip module not available
- Python tarfile not creating valid .tar.gz file
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)
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?
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.