Skip to content

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

Open

Description

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

Activity

  1. dhomeier commented on Jan 28, 2021

    @dhomeier

    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 astropy/astropy#10714 (comment) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions