LEFT | RIGHT |
(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 Loading... |
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 Loading... |
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 } |
LEFT | RIGHT |