OLD | NEW |
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 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "crypto/md5" | 9 "crypto/md5" |
10 "fmt" | 10 "fmt" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 171 } |
172 buf = make([]byte, 6) | 172 buf = make([]byte, 6) |
173 if _, err := io.ReadFull(tr, buf); err != nil { | 173 if _, err := io.ReadFull(tr, buf); err != nil { |
174 t.Fatalf("Unexpected error: %v", err) | 174 t.Fatalf("Unexpected error: %v", err) |
175 } | 175 } |
176 if expected := []byte("Google"); !bytes.Equal(buf, expected) { | 176 if expected := []byte("Google"); !bytes.Equal(buf, expected) { |
177 t.Errorf("Contents = %v, want %v", buf, expected) | 177 t.Errorf("Contents = %v, want %v", buf, expected) |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 | |
182 func TestIncrementalRead(t *testing.T) { | 181 func TestIncrementalRead(t *testing.T) { |
183 test := gnuTarTest | 182 test := gnuTarTest |
184 f, err := os.Open(test.file) | 183 f, err := os.Open(test.file) |
185 if err != nil { | 184 if err != nil { |
186 t.Fatalf("Unexpected error: %v", err) | 185 t.Fatalf("Unexpected error: %v", err) |
187 } | 186 } |
188 defer f.Close() | 187 defer f.Close() |
189 | 188 |
190 tr := NewReader(f) | 189 tr := NewReader(f) |
191 | 190 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 hdr, err := tr.Next() | 264 hdr, err := tr.Next() |
266 if hdr == nil || err == os.EOF { | 265 if hdr == nil || err == os.EOF { |
267 break | 266 break |
268 } | 267 } |
269 } | 268 } |
270 | 269 |
271 if nread != len(test.headers) { | 270 if nread != len(test.headers) { |
272 t.Errorf("Didn't process all files\nexpected: %d\nprocessed %d\n
", len(test.headers), nread) | 271 t.Errorf("Didn't process all files\nexpected: %d\nprocessed %d\n
", len(test.headers), nread) |
273 } | 272 } |
274 } | 273 } |
OLD | NEW |