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 344 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 |