]> Cypherpunks repositories - gostls13.git/commitdiff
archive/zip: add File.DataOffset
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 13 Aug 2013 23:29:51 +0000 (16:29 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 13 Aug 2013 23:29:51 +0000 (16:29 -0700)
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

index 499215328f0546afc436f73b1ae26090d6341893..116737337fb36f0b536a1c4b0c9de21e840f1510 100644 (file)
@@ -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) {