简体   繁体   中英

Python 3.5 tarfile library lzma compresslevel

Is there really no way to set compression level for lzma compression while using the tarfile library? I've read the following:

For modes 'w:gz', 'r:gz', 'w:bz2', 'r:bz2', 'x:gz', 'x:bz2', tarfile.open() accepts the keyword argument compresslevel (default 9) to specify the compression level of the file.

So the documentation obviously tells me no since 'w:xs' is missing here.

But in that case, how do you write a tarfile first and then use the lzma library to convert the tarfile to lzma? All of which must be done using disk storage (files are way too big to store it all in memory, we're talking 2-4gb tarfiles).

For lzma , the option is called preset , as that's the name used in the LZMACompressor class . Set it to an integer between 0 and 9.

See the xzopen() classmethod , used to handle xz compression files.

The documentation is confusing in that it doesn't mention this option explicitly, I'll file an issue to have this improved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM