From: Brad Fitzpatrick Date: Tue, 13 Aug 2013 23:29:51 +0000 (-0700) Subject: archive/zip: add File.DataOffset X-Git-Tag: go1.2rc2~603 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a2599cf50e8f45a19c91c2180468ba0c9d96af0e;p=gostls13.git archive/zip: add File.DataOffset Accessor to find where the bytes of a file start. R=golang-dev, rsc, dsymonds, adg CC=golang-dev https://golang.org/cl/12784045 --- diff --git a/src/pkg/archive/zip/reader.go b/src/pkg/archive/zip/reader.go index 499215328f..116737337f 100644 --- a/src/pkg/archive/zip/reader.go +++ b/src/pkg/archive/zip/reader.go @@ -114,6 +114,19 @@ func (rc *ReadCloser) Close() error { return rc.f.Close() } +// DataOffset returns the offset of the file's possibly-compressed +// data, relative to the beginning of the zip file. +// +// Most callers should instead use Open, which transparently +// decompresses data and verifies checksums. +func (f *File) DataOffset() (offset int64, err error) { + bodyOffset, err := f.findBodyOffset() + if err != nil { + return + } + return f.headerOffset + bodyOffset, nil +} + // Open returns a ReadCloser that provides access to the File's contents. // Multiple files may be read concurrently. func (f *File) Open() (rc io.ReadCloser, err error) {