diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-07-16 06:54:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-07-16 06:54:42 +0000 |
commit | be47d6eceffd2c5dbbc1566d5eea490527fb2bd4 (patch) | |
tree | 0e8fda573576bb4181dba29d0e88380a8c38fafd /libgo/go/compress | |
parent | efb30cdeb003fd7c585ee0d7657340086abcbd9e (diff) | |
download | gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.zip gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.tar.gz gcc-be47d6eceffd2c5dbbc1566d5eea490527fb2bd4.tar.bz2 |
libgo: Update to Go 1.1.1.
From-SVN: r200974
Diffstat (limited to 'libgo/go/compress')
-rw-r--r-- | libgo/go/compress/bzip2/huffman.go | 2 | ||||
-rw-r--r-- | libgo/go/compress/flate/deflate_test.go | 1 | ||||
-rw-r--r-- | libgo/go/compress/flate/inflate.go | 3 | ||||
-rw-r--r-- | libgo/go/compress/flate/token.go | 1 | ||||
-rw-r--r-- | libgo/go/compress/gzip/gunzip.go | 1 | ||||
-rw-r--r-- | libgo/go/compress/gzip/gzip.go | 24 | ||||
-rw-r--r-- | libgo/go/compress/gzip/gzip_test.go | 40 | ||||
-rw-r--r-- | libgo/go/compress/lzw/reader.go | 2 |
8 files changed, 63 insertions, 11 deletions
diff --git a/libgo/go/compress/bzip2/huffman.go b/libgo/go/compress/bzip2/huffman.go index 078c1cb..f755019 100644 --- a/libgo/go/compress/bzip2/huffman.go +++ b/libgo/go/compress/bzip2/huffman.go @@ -54,8 +54,6 @@ func (t huffmanTree) Decode(br *bitReader) (v uint16) { nodeIndex = node.right } } - - panic("unreachable") } // newHuffmanTree builds a Huffman tree from a slice containing the code diff --git a/libgo/go/compress/flate/deflate_test.go b/libgo/go/compress/flate/deflate_test.go index 8f4e196..8c4a6d6 100644 --- a/libgo/go/compress/flate/deflate_test.go +++ b/libgo/go/compress/flate/deflate_test.go @@ -158,7 +158,6 @@ func (b *syncBuffer) Read(p []byte) (n int, err error) { } <-b.ready } - panic("unreachable") } func (b *syncBuffer) signal() { diff --git a/libgo/go/compress/flate/inflate.go b/libgo/go/compress/flate/inflate.go index a8d6460..beca34b 100644 --- a/libgo/go/compress/flate/inflate.go +++ b/libgo/go/compress/flate/inflate.go @@ -263,7 +263,6 @@ func (f *decompressor) Read(b []byte) (int, error) { } f.step(f) } - panic("unreachable") } func (f *decompressor) Close() error { @@ -495,7 +494,6 @@ func (f *decompressor) huffmanBlock() { return } } - panic("unreached") } // copyHist copies f.copyLen bytes from f.hist (f.copyDist bytes ago) to itself. @@ -642,7 +640,6 @@ func (f *decompressor) huffSym(h *huffmanDecoder) (int, error) { return int(chunk >> huffmanValueShift), nil } } - return 0, CorruptInputError(f.roffset) } // Flush any buffered output to the underlying writer. diff --git a/libgo/go/compress/flate/token.go b/libgo/go/compress/flate/token.go index 38aea5f..4d49176 100644 --- a/libgo/go/compress/flate/token.go +++ b/libgo/go/compress/flate/token.go @@ -99,5 +99,4 @@ func offsetCode(off uint32) uint32 { default: return offsetCodes[off>>14] + 28 } - panic("unreachable") } diff --git a/libgo/go/compress/gzip/gunzip.go b/libgo/go/compress/gzip/gunzip.go index 33736f6..1fb9b09 100644 --- a/libgo/go/compress/gzip/gunzip.go +++ b/libgo/go/compress/gzip/gunzip.go @@ -120,7 +120,6 @@ func (z *Reader) readString() (string, error) { return string(z.buf[0:i]), nil } } - panic("not reached") } func (z *Reader) read2() (uint32, error) { diff --git a/libgo/go/compress/gzip/gzip.go b/libgo/go/compress/gzip/gzip.go index 3035dff..45558b7 100644 --- a/libgo/go/compress/gzip/gzip.go +++ b/libgo/go/compress/gzip/gzip.go @@ -28,7 +28,7 @@ type Writer struct { Header w io.Writer level int - compressor io.WriteCloser + compressor *flate.Writer digest hash.Hash32 size uint32 closed bool @@ -191,6 +191,28 @@ func (z *Writer) Write(p []byte) (int, error) { return n, z.err } +// Flush flushes any pending compressed data to the underlying writer. +// +// It is useful mainly in compressed network protocols, to ensure that +// a remote reader has enough data to reconstruct a packet. Flush does +// not return until the data has been written. If the underlying +// writer returns an error, Flush returns that error. +// +// In the terminology of the zlib library, Flush is equivalent to Z_SYNC_FLUSH. +func (z *Writer) Flush() error { + if z.err != nil { + return z.err + } + if z.closed { + return nil + } + if z.compressor == nil { + z.Write(nil) + } + z.err = z.compressor.Flush() + return z.err +} + // Close closes the Writer. It does not close the underlying io.Writer. func (z *Writer) Close() error { if z.err != nil { diff --git a/libgo/go/compress/gzip/gzip_test.go b/libgo/go/compress/gzip/gzip_test.go index 6f7b593..4d1af94 100644 --- a/libgo/go/compress/gzip/gzip_test.go +++ b/libgo/go/compress/gzip/gzip_test.go @@ -157,3 +157,43 @@ func TestLatin1RoundTrip(t *testing.T) { } } } + +func TestWriterFlush(t *testing.T) { + buf := new(bytes.Buffer) + + w := NewWriter(buf) + w.Comment = "comment" + w.Extra = []byte("extra") + w.ModTime = time.Unix(1e8, 0) + w.Name = "name" + + n0 := buf.Len() + if n0 != 0 { + t.Fatalf("buffer size = %d before writes; want 0", n0) + } + + if err := w.Flush(); err != nil { + t.Fatal(err) + } + + n1 := buf.Len() + if n1 == 0 { + t.Fatal("no data after first flush") + } + + w.Write([]byte("x")) + + n2 := buf.Len() + if n1 != n2 { + t.Fatalf("after writing a single byte, size changed from %d to %d; want no change", n1, n2) + } + + if err := w.Flush(); err != nil { + t.Fatal(err) + } + + n3 := buf.Len() + if n2 == n3 { + t.Fatal("Flush didn't flush any data") + } +} diff --git a/libgo/go/compress/lzw/reader.go b/libgo/go/compress/lzw/reader.go index 0ed742c..efbc758 100644 --- a/libgo/go/compress/lzw/reader.go +++ b/libgo/go/compress/lzw/reader.go @@ -121,7 +121,6 @@ func (d *decoder) Read(b []byte) (int, error) { } d.decode() } - panic("unreachable") } // decode decompresses bytes from r and leaves them in d.toRead. @@ -203,7 +202,6 @@ func (d *decoder) decode() { return } } - panic("unreachable") } func (d *decoder) flush() { |