1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// Copyright 2016, Joe Tsai. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.md file.
//go:build !no_lib_uk
// +build !no_lib_uk
package main
import (
"io"
"io/ioutil"
"github.com/ulikunitz/xz/lzma"
)
func init() {
RegisterEncoder(FormatLZMA2, "uk",
func(w io.Writer, lvl int) io.WriteCloser {
// This level conversion logic emulates the conversion found in
// LZMA2Options.java from https://git.tukaani.org/?p=xz-java.git
if lvl < 0 || lvl > 9 {
panic("invalid level")
}
dict := [...]int{
1 << 18, 1 << 20, 1 << 21, 1 << 22, 1 << 22,
1 << 23, 1 << 23, 1 << 24, 1 << 25, 1 << 26,
}[lvl]
match := lzma.HashTable4
// TODO(dsnet): This currently crashes on zero.bin when using
// BinaryTree on revision 76f94b7c69c6f84be96bcfc2443042b198689565.
/*
if lvl > 4 {
match = lzma.BinaryTree
}
*/
zw, err := lzma.Writer2Config{DictCap: dict, Matcher: match}.NewWriter2(w)
if err != nil {
panic(err)
}
return zw
})
RegisterDecoder(FormatLZMA2, "uk",
func(r io.Reader) io.ReadCloser {
zr, err := lzma.NewReader2(r)
if err != nil {
panic(err)
}
return ioutil.NopCloser(zr)
})
}
|