Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 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 package tar | 5 package tar |
6 | 6 |
7 // TODO(dsymonds): | 7 // TODO(dsymonds): |
8 // - pax extensions | 8 // - pax extensions |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 10 matching lines...) Expand all Loading... | |
21 var ( | 21 var ( |
22 ErrHeader = errors.New("archive/tar: invalid tar header") | 22 ErrHeader = errors.New("archive/tar: invalid tar header") |
23 ) | 23 ) |
24 | 24 |
25 const maxNanoSecondIntSize = 9 | 25 const maxNanoSecondIntSize = 9 |
26 | 26 |
27 // A Reader provides sequential access to the contents of a tar archive. | 27 // A Reader provides sequential access to the contents of a tar archive. |
28 // A tar archive consists of a sequence of files. | 28 // A tar archive consists of a sequence of files. |
29 // The Next method advances to the next file in the archive (including the first ), | 29 // The Next method advances to the next file in the archive (including the first ), |
30 // and then it can be treated as an io.Reader to access the file's data. | 30 // and then it can be treated as an io.Reader to access the file's data. |
31 // | |
32 // Example: | |
33 // tr := tar.NewReader(r) | |
34 // for { | |
35 // hdr, err := tr.Next() | |
36 // if err == io.EOF { | |
37 // // end of tar archive | |
38 // break | |
39 // } | |
40 // if err != nil { | |
41 // // handle error | |
42 // } | |
43 // io.Copy(data, tr) | |
44 // } | |
45 type Reader struct { | 31 type Reader struct { |
46 r io.Reader | 32 r io.Reader |
47 err error | 33 err error |
48 nb int64 // number of unread bytes for current file entry | 34 nb int64 // number of unread bytes for current file entry |
49 pad int64 // amount of padding (ignored) after current file entry | 35 pad int64 // amount of padding (ignored) after current file entry |
50 } | 36 } |
51 | 37 |
52 // NewReader creates a new Reader reading from r. | 38 // NewReader creates a new Reader reading from r. |
53 func NewReader(r io.Reader) *Reader { return &Reader{r: r} } | 39 func NewReader(r io.Reader) *Reader { return &Reader{r: r} } |
54 | 40 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 // If a NUL byte is not found then the whole slice is returned as a string. | 224 // If a NUL byte is not found then the whole slice is returned as a string. |
239 func cString(b []byte) string { | 225 func cString(b []byte) string { |
240 n := 0 | 226 n := 0 |
241 for n < len(b) && b[n] != 0 { | 227 for n < len(b) && b[n] != 0 { |
242 n++ | 228 n++ |
243 } | 229 } |
244 return string(b[0:n]) | 230 return string(b[0:n]) |
245 } | 231 } |
246 | 232 |
247 func (tr *Reader) octal(b []byte) int64 { | 233 func (tr *Reader) octal(b []byte) int64 { |
248 // Check for binary format first. | 234 // Check for binary format first. |
dsymonds
2013/01/09 02:13:17
This is already in the tree; I think you need to s
shanemhansen
2013/01/09 02:40:28
Done. I think. I certainly did a hg sync and hg up
| |
249 if len(b) > 0 && b[0]&0x80 != 0 { | 235 if len(b) > 0 && b[0]&0x80 != 0 { |
250 var x int64 | 236 var x int64 |
251 for i, c := range b { | 237 for i, c := range b { |
252 if i == 0 { | 238 if i == 0 { |
253 c &= 0x7f // ignore signal bit in first byte | 239 c &= 0x7f // ignore signal bit in first byte |
254 } | 240 } |
255 x = x<<8 | int64(c) | 241 x = x<<8 | int64(c) |
256 } | 242 } |
257 return x | 243 return x |
258 } | 244 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 } | 385 } |
400 n, err = tr.r.Read(b) | 386 n, err = tr.r.Read(b) |
401 tr.nb -= int64(n) | 387 tr.nb -= int64(n) |
402 | 388 |
403 if err == io.EOF && tr.nb > 0 { | 389 if err == io.EOF && tr.nb > 0 { |
404 err = io.ErrUnexpectedEOF | 390 err = io.ErrUnexpectedEOF |
405 } | 391 } |
406 tr.err = err | 392 tr.err = err |
407 return | 393 return |
408 } | 394 } |
LEFT | RIGHT |