Skip to content

archive/zip: not possible to a start writing zip at offset other than zero #8669

Description

@gopherbot

by sanderhahn:

go version go1.3.1 darwin/amd64

The zip api doesn't allow creating a zip file with a different offset than zero. This is
relevant for instance if a zip file is appended to an existing binary. The reader reads
the zip contents alright but only when the offsets are first corrected using the
"zip -A" command.

I understand this is not a high priority issue, but it would be nice to have a pure go
way of creating zips at an offset other than zero. For instance if you want to embed
files into your own binary.

The solution that i see that would not break the existing API is providing an additional
construtor that takes the initial count value for the countWriter:

// writer.go

func NewWriterAt(w io.Writer, count int64) *Writer {
    return &Writer{cw: &countWriter{w: bufio.NewWriter(w), count: count}}
}

Another solution would be to make the zip reader smarter and automatically correct the
offsets if they are not correct (as the unzip tool does).

Is it possible to consider this additional constructor in a new release?

An example program that uses a patched version of the stdlib zip to add zip contents to
an existing binary is at: https://github.com/sanderhahn/gozip

Thank you for the great language and tooling :)

Best regards,
Sander Hahn

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions