示例#1
0
文件: lz4_test.go 项目: shenjinxi/lz4
// Test low levels core functions:
// a. compress and compare with supplied data if any
// b. decompress the previous data and compare it with the original one
func TestBlock(t *testing.T) {
	for _, compress := range []func([]byte, []byte, int) (int, error){
		lz4.CompressBlock,
		lz4.CompressBlockHC,
	} {
		for _, item := range testDataItems {
			data := item.data
			z := make([]byte, lz4.CompressBlockBound(len(data)))
			n, err := compress(data, z, 0)
			if n == 0 { // not compressible
				continue
			}
			if err != nil {
				t.Errorf("CompressBlock: %s", err)
				t.FailNow()
			}
			z = z[:n]
			d := make([]byte, len(data))
			n, err = lz4.UncompressBlock(z, d, 0)
			if err != nil {
				t.Errorf("UncompressBlock: %s", err)
				t.FailNow()
			}
			d = d[:n]
			if !bytes.Equal(d, data) {
				t.Errorf("invalid decompressed data: %s: %s", item.label, string(d))
				t.FailNow()
			}
		}
	}
}
示例#2
0
文件: lz4_test.go 项目: shenjinxi/lz4
func BenchmarkUncompressBlock(b *testing.B) {
	d := make([]byte, len(lorem))
	z := make([]byte, len(lorem))
	n, err := lz4.CompressBlock(lorem, z, 0)
	if err != nil {
		b.Errorf("CompressBlock: %s", err)
		b.FailNow()
	}
	z = z[:n]
	for i := 0; i < b.N; i++ {
		lz4.UncompressBlock(z, d, 0)
	}
}
示例#3
0
func (_ Test) LZ4Compress() {
	var b = []byte("dette er en test af LZ4 komprimering")
	e.InfoLog.Println(string(b))
	b = testData

	var compressed = make([]byte, len(b))
	size, err := lz4.CompressBlockHC(b, compressed, 0)
	if err != nil || size == 0 {
		e.InfoLog.Println(err, size)
	}
	compressed = compressed[:size]

	var out = make([]byte, len(b))
	_, err = lz4.UncompressBlock(compressed, out, 0)
	if err != nil {
		e.InfoLog.Println(err, size)
	}

	e.InfoLog.Println("Result of LZ4 compression: ", len(b), size)
}