diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-03-02 16:38:43 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-03-02 16:38:43 +0000 |
commit | cbb6491d76c7aa81cdf5d3b3a81386129c5e2fce (patch) | |
tree | efa0c55763b34cbc633bc494c2743d1b5d9aaff3 /libgo/go/archive | |
parent | ff2f581b00ac6759f6366c16ef902c935163aa13 (diff) | |
download | gcc-cbb6491d76c7aa81cdf5d3b3a81386129c5e2fce.zip gcc-cbb6491d76c7aa81cdf5d3b3a81386129c5e2fce.tar.gz gcc-cbb6491d76c7aa81cdf5d3b3a81386129c5e2fce.tar.bz2 |
libgo: Update to weekly.2012-02-14 release.
From-SVN: r184798
Diffstat (limited to 'libgo/go/archive')
-rw-r--r-- | libgo/go/archive/zip/reader_test.go | 11 | ||||
-rw-r--r-- | libgo/go/archive/zip/writer.go | 80 | ||||
-rw-r--r-- | libgo/go/archive/zip/writer_test.go | 2 | ||||
-rw-r--r-- | libgo/go/archive/zip/zip_test.go | 16 |
4 files changed, 48 insertions, 61 deletions
diff --git a/libgo/go/archive/zip/reader_test.go b/libgo/go/archive/zip/reader_test.go index 935860e..ea9e002 100644 --- a/libgo/go/archive/zip/reader_test.go +++ b/libgo/go/archive/zip/reader_test.go @@ -278,7 +278,7 @@ func TestInvalidFiles(t *testing.T) { b := make([]byte, size) // zeroes - _, err := NewReader(sliceReaderAt(b), size) + _, err := NewReader(bytes.NewReader(b), size) if err != ErrFormat { t.Errorf("zeroes: error=%v, want %v", err, ErrFormat) } @@ -289,15 +289,8 @@ func TestInvalidFiles(t *testing.T) { for i := 0; i < size-4; i += 4 { copy(b[i:i+4], sig) } - _, err = NewReader(sliceReaderAt(b), size) + _, err = NewReader(bytes.NewReader(b), size) if err != ErrFormat { t.Errorf("sigs: error=%v, want %v", err, ErrFormat) } } - -type sliceReaderAt []byte - -func (r sliceReaderAt) ReadAt(b []byte, off int64) (int, error) { - copy(b, r[int(off):int(off)+len(b)]) - return len(b), nil -} diff --git a/libgo/go/archive/zip/writer.go b/libgo/go/archive/zip/writer.go index a4f0654..c591aed 100644 --- a/libgo/go/archive/zip/writer.go +++ b/libgo/go/archive/zip/writer.go @@ -19,7 +19,7 @@ import ( // Writer implements a zip file writer. type Writer struct { - countWriter + cw *countWriter dir []*header last *fileWriter closed bool @@ -32,7 +32,7 @@ type header struct { // NewWriter returns a new Writer writing a zip file to w. func NewWriter(w io.Writer) *Writer { - return &Writer{countWriter: countWriter{w: bufio.NewWriter(w)}} + return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}} } // Close finishes writing the zip file by writing the central directory. @@ -52,42 +52,42 @@ func (w *Writer) Close() (err error) { defer recoverError(&err) // write central directory - start := w.count + start := w.cw.count for _, h := range w.dir { - write(w, uint32(directoryHeaderSignature)) - write(w, h.CreatorVersion) - write(w, h.ReaderVersion) - write(w, h.Flags) - write(w, h.Method) - write(w, h.ModifiedTime) - write(w, h.ModifiedDate) - write(w, h.CRC32) - write(w, h.CompressedSize) - write(w, h.UncompressedSize) - write(w, uint16(len(h.Name))) - write(w, uint16(len(h.Extra))) - write(w, uint16(len(h.Comment))) - write(w, uint16(0)) // disk number start - write(w, uint16(0)) // internal file attributes - write(w, h.ExternalAttrs) - write(w, h.offset) - writeBytes(w, []byte(h.Name)) - writeBytes(w, h.Extra) - writeBytes(w, []byte(h.Comment)) + write(w.cw, uint32(directoryHeaderSignature)) + write(w.cw, h.CreatorVersion) + write(w.cw, h.ReaderVersion) + write(w.cw, h.Flags) + write(w.cw, h.Method) + write(w.cw, h.ModifiedTime) + write(w.cw, h.ModifiedDate) + write(w.cw, h.CRC32) + write(w.cw, h.CompressedSize) + write(w.cw, h.UncompressedSize) + write(w.cw, uint16(len(h.Name))) + write(w.cw, uint16(len(h.Extra))) + write(w.cw, uint16(len(h.Comment))) + write(w.cw, uint16(0)) // disk number start + write(w.cw, uint16(0)) // internal file attributes + write(w.cw, h.ExternalAttrs) + write(w.cw, h.offset) + writeBytes(w.cw, []byte(h.Name)) + writeBytes(w.cw, h.Extra) + writeBytes(w.cw, []byte(h.Comment)) } - end := w.count + end := w.cw.count // write end record - write(w, uint32(directoryEndSignature)) - write(w, uint16(0)) // disk number - write(w, uint16(0)) // disk number where directory starts - write(w, uint16(len(w.dir))) // number of entries this disk - write(w, uint16(len(w.dir))) // number of entries total - write(w, uint32(end-start)) // size of directory - write(w, uint32(start)) // start of directory - write(w, uint16(0)) // size of comment + write(w.cw, uint32(directoryEndSignature)) + write(w.cw, uint16(0)) // disk number + write(w.cw, uint16(0)) // disk number where directory starts + write(w.cw, uint16(len(w.dir))) // number of entries this disk + write(w.cw, uint16(len(w.dir))) // number of entries total + write(w.cw, uint32(end-start)) // size of directory + write(w.cw, uint32(start)) // start of directory + write(w.cw, uint16(0)) // size of comment - return w.w.(*bufio.Writer).Flush() + return w.cw.w.(*bufio.Writer).Flush() } // Create adds a file to the zip file using the provided name. @@ -119,15 +119,19 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) { fh.ReaderVersion = 0x14 fw := &fileWriter{ - zipw: w, - compCount: &countWriter{w: w}, + zipw: w.cw, + compCount: &countWriter{w: w.cw}, crc32: crc32.NewIEEE(), } switch fh.Method { case Store: fw.comp = nopCloser{fw.compCount} case Deflate: - fw.comp = flate.NewWriter(fw.compCount, 5) + var err error + fw.comp, err = flate.NewWriter(fw.compCount, 5) + if err != nil { + return nil, err + } default: return nil, ErrAlgorithm } @@ -135,12 +139,12 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) { h := &header{ FileHeader: fh, - offset: uint32(w.count), + offset: uint32(w.cw.count), } w.dir = append(w.dir, h) fw.header = h - if err := writeHeader(w, fh); err != nil { + if err := writeHeader(w.cw, fh); err != nil { return nil, err } diff --git a/libgo/go/archive/zip/writer_test.go b/libgo/go/archive/zip/writer_test.go index ce93fae..88e5211 100644 --- a/libgo/go/archive/zip/writer_test.go +++ b/libgo/go/archive/zip/writer_test.go @@ -77,7 +77,7 @@ func TestWriter(t *testing.T) { } // read it back - r, err := NewReader(sliceReaderAt(buf.Bytes()), int64(buf.Len())) + r, err := NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len())) if err != nil { t.Fatal(err) } diff --git a/libgo/go/archive/zip/zip_test.go b/libgo/go/archive/zip/zip_test.go index 1a260cc..d6490c4 100644 --- a/libgo/go/archive/zip/zip_test.go +++ b/libgo/go/archive/zip/zip_test.go @@ -9,22 +9,12 @@ package zip import ( "bytes" "fmt" - "io" "reflect" + "strings" "testing" "time" ) -type stringReaderAt string - -func (s stringReaderAt) ReadAt(p []byte, off int64) (n int, err error) { - if off >= int64(len(s)) { - return 0, io.EOF - } - n = copy(p, s[off:]) - return -} - func TestOver65kFiles(t *testing.T) { if testing.Short() { t.Logf("slow test; skipping") @@ -42,8 +32,8 @@ func TestOver65kFiles(t *testing.T) { if err := w.Close(); err != nil { t.Fatalf("Writer.Close: %v", err) } - rat := stringReaderAt(buf.String()) - zr, err := NewReader(rat, int64(len(rat))) + s := buf.String() + zr, err := NewReader(strings.NewReader(s), int64(len(s))) if err != nil { t.Fatalf("NewReader: %v", err) } |