mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-22 00:08:04 +02:00
Simplify stream decompressor
This commit is contained in:
36
tools/utils/stream_decompressor_test.go
Normal file
36
tools/utils/stream_decompressor_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func TestStreamDecompressor(t *testing.T) {
|
||||
input := make([]byte, 9723)
|
||||
io.ReadFull(rand.Reader, input)
|
||||
b := bytes.Buffer{}
|
||||
w := zlib.NewWriter(&b)
|
||||
io.Copy(w, bytes.NewReader(input))
|
||||
w.Close()
|
||||
o := bytes.Buffer{}
|
||||
sd := NewStreamDecompressor(zlib.NewReader, &o)
|
||||
data := b.Bytes()
|
||||
for len(data) > 0 {
|
||||
chunk := data[:Min(117, len(data))]
|
||||
data = data[len(chunk):]
|
||||
if err := sd(chunk, len(data) == 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if !bytes.Equal(o.Bytes(), input) {
|
||||
t.Fatalf("Roundtripping via zlib failed output (%d) != input (%d)", len(o.Bytes()), len(input))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user