From a2599cf50e8f45a19c91c2180468ba0c9d96af0e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 13 Aug 2013 16:29:51 -0700 Subject: [PATCH] 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 --- src/pkg/archive/zip/reader.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) { -- 2.48.1