Example #1
0
func NewWriter(w io.Writer, preset Preset) (*Compressor, error) {
	enc := new(Compressor)
	// The zero lzma_stream is the same thing as LZMA_STREAM_INIT.
	enc.writer = w
	enc.buffer = make([]byte, DefaultBufsize)
	enc.handle = allocLzmaStream(enc.handle)
	// Initialize encoder
	ret := C.lzma_easy_encoder(enc.handle, C.uint32_t(preset), C.lzma_check(CheckCRC64))
	if Errno(ret) != Ok {
		return nil, Errno(ret)
	}

	return enc, nil
}
Example #2
0
// Initializes a XZ encoder with additional settings.
func NewWriterCustom(w io.Writer, preset Preset, check Checksum, bufsize int) (*Compressor, error) {
	enc := new(Compressor)
	// The zero lzma_stream is the same thing as LZMA_STREAM_INIT.
	enc.writer = w
	enc.buffer = make([]byte, bufsize)

	// Initialize encoder
	ret := C.lzma_easy_encoder(&enc.handle, C.uint32_t(preset), C.lzma_check(check))
	if Errno(ret) != Ok {
		return nil, Errno(ret)
	}

	return enc, nil
}