5

I am using Python 3.6, and currently I subprocess out to my 7zip program to get the compression I need.

subprocess.call('7z a -t7z -ms=off {0} *'.format(filename))

I know the zipfile class has ‘ZIP_LZMA’ compression, but the application I am passing this too says the output file isn’t correct. So what else do I have to add to the ZipFile class to make it mimic the above command?

JabberJabber
  • 341
  • 2
  • 17

1 Answers1

2

If you do not care much for Windows, then perhaps libarchive could help. In Ubuntu, for example:

$ sudo apt install python3-libarchive-c

Then:

import libarchive
with libarchive.file_writer('test.7z', '7zip') as archive:
    archive.add_files('first.file', 'second.file', 'third.file')

Then there is the pylib7zip library, which wraps the existing 7z.dll and seems to offer a Windows-only alternative.

KT.
  • 10,815
  • 4
  • 47
  • 71
  • Also lib archive-c seems to fail on build – JabberJabber May 23 '18 at 23:43
  • Pylib7zip is a wrapper around 7z.dll, hence in theory one should be able to squeeze the compression out of it as well - the existence of the FileOutStream class does give some hope. – KT. May 23 '18 at 23:58
  • To build python_libarchive_c you'd probably need to install the necessary dependencies (e.g. libarchive-dev). The pre-built Ubuntu package somehow works, after all. – KT. May 24 '18 at 00:00