forked from mirror/brotli
parent
f001d275a3
commit
786ec621f6
|
@ -345,6 +345,22 @@ func TestReader(t *testing.T) {
|
|||
"<%d bytes>",
|
||||
got, len(content))
|
||||
}
|
||||
|
||||
r.Reset(bytes.NewReader(encoded))
|
||||
decodedOutput.Reset()
|
||||
n, err = io.Copy(&decodedOutput, r)
|
||||
if err != nil {
|
||||
t.Fatalf("After Reset: Copy(): n=%v, err=%v", n, err)
|
||||
}
|
||||
if got := decodedOutput.Bytes(); !bytes.Equal(got, content) {
|
||||
t.Errorf("After Reset: "+
|
||||
"Reader output:\n"+
|
||||
"%q\n"+
|
||||
"want:\n"+
|
||||
"<%d bytes>",
|
||||
got, len(content))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestDecode(t *testing.T) {
|
||||
|
|
17
decode.go
17
decode.go
|
@ -1304,26 +1304,21 @@ func wrapRingBuffer(s *Reader) {
|
|||
Last two bytes of ring-buffer are initialized to 0, so context calculation
|
||||
could be done uniformly for the first two and all other positions. */
|
||||
func ensureRingBuffer(s *Reader) bool {
|
||||
var old_ringbuffer []byte = s.ringbuffer
|
||||
var old_ringbuffer []byte
|
||||
if s.ringbuffer_size == s.new_ringbuffer_size {
|
||||
return true
|
||||
}
|
||||
|
||||
s.ringbuffer = make([]byte, uint(s.new_ringbuffer_size)+uint(kRingBufferWriteAheadSlack))
|
||||
if s.ringbuffer == nil {
|
||||
/* Restore previous value. */
|
||||
s.ringbuffer = old_ringbuffer
|
||||
|
||||
return false
|
||||
spaceNeeded := int(s.new_ringbuffer_size) + int(kRingBufferWriteAheadSlack)
|
||||
if len(s.ringbuffer) < spaceNeeded {
|
||||
old_ringbuffer = s.ringbuffer
|
||||
s.ringbuffer = make([]byte, spaceNeeded)
|
||||
}
|
||||
|
||||
s.ringbuffer[s.new_ringbuffer_size-2] = 0
|
||||
s.ringbuffer[s.new_ringbuffer_size-1] = 0
|
||||
|
||||
if !(old_ringbuffer == nil) {
|
||||
if old_ringbuffer != nil {
|
||||
copy(s.ringbuffer, old_ringbuffer[:uint(s.pos)])
|
||||
|
||||
old_ringbuffer = nil
|
||||
}
|
||||
|
||||
s.ringbuffer_size = s.new_ringbuffer_size
|
||||
|
|
Loading…
Reference in New Issue