Skip to content

compress/zlib: reading data with known length #14867

Closed
@ghost

Description

When the length of the compressed data is known a priori, and one reads precisely as many bytes from the ReadCloser returned by zlib.NewReader, the zlib checksum isn't read. One needs to attempt to read past the end of the compressed stream to get zlib to read it, which I think this is counterintuitive, and makes it so that one pretty much has to use ioutil.ReadAll to safely read zlibbed segments embedded in a larger stream.

Obligatory play.golang.org link: https://play.golang.org/p/KvqnDU36Q2

A good solution, I think, would be to arrange to have Close read and check the checksum if it hasn't been done yet, as it should be called when one is done reading anyway.

Tested on go1.5 linux/amd64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions