leaty
leaty

Reputation: 23

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).

Upvotes: 2

Views: 582

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1125398

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.

Upvotes: 4

Related Questions