ionelmc / python-unlzw

BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

Can't unpack archive that can be properly unpacked by gunzip #2

Open infy-infy opened 4 years ago

infy-infy commented 4 years ago

It gives an error: "Stream ended in the middle of a code." Code that reproduces bug:

    filename = "igsg2260.15i.Z"
    if filename.upper().endswith(".Z"):
        from unlzw import unlzw
        with open(filename, "rb") as file_compr:
            try:
                file_raw = unlzw(file_compr.read()).decode('UTF-8')
            except ValueError as e:
                print("unlzw: can't unpack .Z archive with error:\n'{}'".format(e))

gunzip extract file without problems. Github doesn't allow to attach .Z files directly, so I put it in zip archive, you'll need to unpack it first. igsg2260.15i.Z.zip

dhomeier commented 3 years ago

Is this package still maintained? Noticed a similar problem when trying to use unlzw for uncompressing binary data, and I think the problem described here https://github.com/astropy/astropy/issues/10714#issuecomment-769319604 comes down to calling

        return _ffi.string(out[0], outlen[0])

in __init__.py, which truncates the data buffer at the first null character – changing this to

        return _ffi.buffer(out[0], outlen[0])[:]

worked for my examples.

EDIT: The above may not be relevant for this issue, which is a case of unlzw returning retcode=-3 – looking at the file it seems that it might be missing an EOL/EOF; the last line of that file (uncompressed) looks incomplete. I guess that does not necessarily mean its contents cannot be unpacked, so perhaps the return value -3 could be handled differently, raising just a warning or adding an option to override the ValueError.