I need to create a tar.gzipped text file. Is there a way to create a file for permanent recording (to do something like compressedFile.write("some text") ), or do I need to create the original text file first and compress it after that?
compressedFile.write("some text")
This will be very unfortunate, as the file must be very long and well compressible.
Here is an example of how to write a compressed tar file from a Python script:
import StringIO import tarfile tar = tarfile.open('example.tar.gz', 'w:gz') # create a file record data = StringIO.StringIO('this is some text') info = tar.tarinfo() info.name = 'foo.txt' info.uname = 'pat' info.gname = 'users' info.size = data.len # add the file to the tar and close it tar.addfile(info, data) tar.close()
Result:
% tar tvf example.tar.gz -rw-r--r-- 0 pat users 17 Dec 31 1969 foo.txt
Source: https://habr.com/ru/post/886011/More articles:With CXF (actually GroovyWS), how do I create a SOAP header with one child node with text node? - web-servicesHow do I manage the development and deployment of my website as a team? - phpQuestion about the pie template - scalaTFS 2010 Team Build - rename file - tfsPrint on one line with a pause on C - cHow to get dispayfield in extjs combo? - extjsHow to associate a ComboBox with a shared list with the deep DisplayMember and ValueMember properties? - c #A field or property with the name was not found in the selected data source - vb.netWindbg: creating a log of input and output functions - windbgBest practice for displaying text in Java? - javaAll Articles