Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(851)

Delta Between Two Patch Sets: src/pkg/archive/zip/reader.go

Issue 4344062: code review 4344062: os: add Seek whence constants (Closed)
Left Patch Set: diff -r 091dac2e0b87 https://go.googlecode.com/hg Created 13 years, 11 months ago
Right Patch Set: diff -r 6945f9e0915c https://go.googlecode.com/hg Created 13 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/archive/tar/reader.go ('k') | src/pkg/debug/elf/file.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* 5 /*
6 The zip package provides support for reading ZIP archives. 6 The zip package provides support for reading ZIP archives.
7 7
8 See: http://www.pkware.com/documents/casestudies/APPNOTE.TXT 8 See: http://www.pkware.com/documents/casestudies/APPNOTE.TXT
9 9
10 This package does not support ZIP64 or disk spanning. 10 This package does not support ZIP64 or disk spanning.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 end, err := readDirectoryEnd(r, size) 66 end, err := readDirectoryEnd(r, size)
67 if err != nil { 67 if err != nil {
68 return nil, err 68 return nil, err
69 } 69 }
70 z := &Reader{ 70 z := &Reader{
71 r: r, 71 r: r,
72 File: make([]*File, end.directoryRecords), 72 File: make([]*File, end.directoryRecords),
73 Comment: end.comment, 73 Comment: end.comment,
74 } 74 }
75 rs := io.NewSectionReader(r, 0, size) 75 rs := io.NewSectionReader(r, 0, size)
76 » if _, err = rs.Seek(int64(end.directoryOffset), 0); err != nil { 76 » if _, err = rs.Seek(int64(end.directoryOffset), os.SEEK_SET); err != nil {
77 return nil, err 77 return nil, err
78 } 78 }
79 buf := bufio.NewReader(rs) 79 buf := bufio.NewReader(rs)
80 for i := range z.File { 80 for i := range z.File {
81 z.File[i] = &File{zipr: r, zipsize: size} 81 z.File[i] = &File{zipr: r, zipsize: size}
82 if err := readDirectoryHeader(z.File[i], buf); err != nil { 82 if err := readDirectoryHeader(z.File[i], buf); err != nil {
83 return nil, err 83 return nil, err
84 } 84 }
85 } 85 }
86 return z, nil 86 return z, nil
87 } 87 }
88 88
89 // Open returns a ReadCloser that provides access to the File's contents. 89 // Open returns a ReadCloser that provides access to the File's contents.
90 func (f *File) Open() (rc io.ReadCloser, err os.Error) { 90 func (f *File) Open() (rc io.ReadCloser, err os.Error) {
91 off := int64(f.headerOffset) 91 off := int64(f.headerOffset)
92 if f.bodyOffset == 0 { 92 if f.bodyOffset == 0 {
93 r := io.NewSectionReader(f.zipr, off, f.zipsize-off) 93 r := io.NewSectionReader(f.zipr, off, f.zipsize-off)
94 if err = readFileHeader(f, r); err != nil { 94 if err = readFileHeader(f, r); err != nil {
95 return 95 return
96 } 96 }
97 » » if f.bodyOffset, err = r.Seek(0, 1); err != nil { 97 » » if f.bodyOffset, err = r.Seek(0, os.SEEK_CUR); err != nil {
98 return 98 return
99 } 99 }
100 } 100 }
101 size := int64(f.CompressedSize) 101 size := int64(f.CompressedSize)
102 if f.hasDataDescriptor() { 102 if f.hasDataDescriptor() {
103 if size == 0 { 103 if size == 0 {
104 // permit SectionReader to see the rest of the file 104 // permit SectionReader to see the rest of the file
105 size = f.zipsize - (off + f.bodyOffset) 105 size = f.zipsize - (off + f.bodyOffset)
106 } else { 106 } else {
107 size += dataDescriptorLen 107 size += dataDescriptorLen
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 func readByteSlice(r io.Reader, l uint16) []byte { 295 func readByteSlice(r io.Reader, l uint16) []byte {
296 b := make([]byte, l) 296 b := make([]byte, l)
297 if l == 0 { 297 if l == 0 {
298 return b 298 return b
299 } 299 }
300 if _, err := io.ReadFull(r, b); err != nil { 300 if _, err := io.ReadFull(r, b); err != nil {
301 panic(err) 301 panic(err)
302 } 302 }
303 return b 303 return b
304 } 304 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b