Merge branch 'issue22'

This commit is contained in:
Andy Balholm 2021-07-15 12:01:52 -07:00
commit e073f0d4ed
2 changed files with 42 additions and 0 deletions

View File

@ -7,11 +7,13 @@ package brotli
import ( import (
"bytes" "bytes"
"compress/gzip"
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"math" "math"
"math/rand" "math/rand"
"os"
"testing" "testing"
"time" "time"
) )
@ -105,6 +107,46 @@ func TestWriter(t *testing.T) {
} }
} }
func TestIssue22(t *testing.T) {
f, err := os.Open("testdata/issue22.gz")
if err != nil {
t.Fatalf("Error opening test data file: %v", err)
}
defer f.Close()
zr, err := gzip.NewReader(f)
if err != nil {
t.Fatalf("Error creating gzip reader: %v", err)
}
data, err := io.ReadAll(zr)
if err != nil {
t.Fatalf("Error reading test data: %v", err)
}
if len(data) != 2851073 {
t.Fatalf("Wrong length for test data: got %d, want 2851073", len(data))
}
for level := BestSpeed; level <= BestCompression; level++ {
out := bytes.Buffer{}
e := NewWriterOptions(&out, WriterOptions{Quality: level})
n, err := e.Write(data)
if err != nil {
t.Errorf("Error compressing data: %v", err)
}
if int(n) != len(data) {
t.Errorf("Write() n=%v, want %v", n, len(data))
}
if err := e.Close(); err != nil {
t.Errorf("Close Error after writing %d bytes: %v", n, err)
}
if err := checkCompressedData(out.Bytes(), data); err != nil {
t.Errorf("Error decompressing data at level %d: %v", level, err)
}
}
}
func TestEncoderStreams(t *testing.T) { func TestEncoderStreams(t *testing.T) {
// Test that output is streamed. // Test that output is streamed.
// Adjust window size to ensure the encoder outputs at least enough bytes // Adjust window size to ensure the encoder outputs at least enough bytes

BIN
testdata/issue22.gz vendored Normal file

Binary file not shown.