From 5dcf59bdf4b1a63ca8733994a81c936becf59933 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 3 Nov 2014 00:29:34 +0100 Subject: Forgot to put in regular bytes during decompression --- compression/rle/read_write.go | 2 ++ compression/rle/read_write_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) (limited to 'compression') diff --git a/compression/rle/read_write.go b/compression/rle/read_write.go index e6f78e372..b4b73dab4 100644 --- a/compression/rle/read_write.go +++ b/compression/rle/read_write.go @@ -37,6 +37,8 @@ func Decompress(dat []byte) ([]byte, error) { } else { return nil, errors.New("error reading bytes. token encountered without proceeding bytes") } + } else { + buf.WriteByte(dat[i]) } } diff --git a/compression/rle/read_write_test.go b/compression/rle/read_write_test.go index 944822a47..76ceb6350 100644 --- a/compression/rle/read_write_test.go +++ b/compression/rle/read_write_test.go @@ -91,3 +91,25 @@ func TestCompressMulti(t *testing.T) { t.Error("expected", exp, "got", res) } } + +func TestCompressDecompress(t *testing.T) { + var in []byte + + for i := 0; i < 20; i++ { + in = append(in, []byte{0, 0, 0, 0, 0}...) + in = append(in, crypto.Sha3([]byte(""))...) + in = append(in, crypto.Sha3([]byte{0x80})...) + in = append(in, []byte{123, 2, 19, 89, 245, 254, 255, token, 98, 233}...) + in = append(in, token) + } + + c := Compress(in) + d, err := Decompress(c) + if err != nil { + t.Error(err) + } + + if bytes.Compare(d, in) != 0 { + t.Error("multi failed\n", d, "\n", in) + } +} -- cgit