fancycode / pylzma

Python bindings for the LZMA library
http://www.joachim-bauch.de/projects/pylzma/
GNU Lesser General Public License v2.1
234 stars 72 forks source link

Can't decompress the lzma1900.7z file using py7zlib.Archive7z #65

Open funcman opened 5 years ago

funcman commented 5 years ago

This is my code:

import sys

if (sys.version_info > (3, 0)):
    import urllib.request as urllib
else:
    import urllib2 as urllib

import os
import py7zlib

def download(url, output):
    data = urllib.urlopen(url)
    with open(output, "wb") as f:
        f.write(data.read())

def check_dir(dir):
    if (os.path.isdir(dir)):
        pass
    else:
        os.makedirs(dir)

def dec_7z(file_name, output):
    with open(file_name, 'rb') as f:
        archive = py7zlib.Archive7z(f)
        for name in archive.getnames():
            print(name)
            outfilename = os.path.join(output, name)
            outdir = os.path.dirname(outfilename)
            check_dir(outdir)
            with open(outfilename, 'wb') as outfile:
                outfile.write(archive.getmember(name).read())

url = "https://sourceforge.net/projects/sevenzip/files/LZMA%20SDK/lzma1900.7z/download"
file_name = "lzma1900.7z"

download(url, file_name)
dec_7z(file_name, "7z")

Run it, but get this:

...
Java/SevenZip/Compression/RangeCoder/Decoder.java
Java/SevenZip/Compression/RangeCoder/Encoder.java
Java/SevenZip/CRC.java
Java/SevenZip/ICodeProgress.java
Java/SevenZip/LzmaAlone.java
Traceback (most recent call last):
  File "down7z.py", line 37, in <module>
    dec_7z(file_name, "7z")
  File "down7z.py", line 31, in dec_7z
    outfile.write(archive.getmember(name).read())
  File "C:\ProgramData\Anaconda3\envs\py27\lib\site-packages\py7zlib.py", line 6
32, in read
    data = getattr(self, decoder)(coder, data, level, num_coders)
  File "C:\ProgramData\Anaconda3\envs\py27\lib\site-packages\py7zlib.py", line 7
02, in _read_lzma
    return self._read_from_decompressor(coder, dec, input, level, num_coders, wi
th_cache=True)
  File "C:\ProgramData\Anaconda3\envs\py27\lib\site-packages\py7zlib.py", line 6
70, in _read_from_decompressor
    tmp = decompressor.decompress(data)
ValueError: data error during decompression

And my env:

>uname
MINGW32_NT-6.1

>pip search pylzma
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Ple
ase upgrade your Python as Python 2.7 won't be maintained after that date. A fut
ure version of pip will drop support for Python 2.7.
pylzma (0.5.0)  - Python bindings for the LZMA library by Igor Pavlov.
  INSTALLED: 0.5.0 (latest)

Thanks!

BiatuAutMiahn commented 4 years ago

Still and issue:

Java/SevenZip/Compression/RangeCoder/Decoder.java
Java/SevenZip/Compression/RangeCoder/Encoder.java
Java/SevenZip/CRC.java
Java/SevenZip/ICodeProgress.java
Java/SevenZip/LzmaAlone.java
Traceback (most recent call last):
  File "test.py", line 37, in <module>
    dec_7z(file_name, "7z")
  File "test.py", line 31, in dec_7z
    outfile.write(archive.getmember(name).read())
  File "C:\Program Files\Python37\lib\site-packages\py7zlib.py", line 650, in read
    data = getattr(self, decoder)(coder, data, level, num_coders)
  File "C:\Program Files\Python37\lib\site-packages\py7zlib.py", line 735, in _read_lzma
    return self._read_from_decompressor(coder, dec, input, level, num_coders, with_cache=True)
  File "C:\Program Files\Python37\lib\site-packages\py7zlib.py", line 698, in _read_from_decompressor
    tmp = decompressor.decompress(data)
ValueError: data error during decompression

image