Exemplo n.º 1
0
// NewWriter returns a writer for bzip2-compressed streams.
func NewWriter(out io.Writer) io.WriteCloser {
	const blockSize = 9
	const verbosity = 0
	const workFactor = 30
	w := &writer{w: out, stream: C.bz2alloc()}
	C.BZ2_bzCompressInit(w.stream, blockSize, verbosity, workFactor)
	return w
}
Exemplo n.º 2
0
// NewWriter returns a writer for bzip2-compressed streams.
func NewWriter(out io.Writer) io.WriteCloser {
	const (
		blockSize  = 9
		verbosity  = 0
		workFactor = 30
	)
	w := &writer{w: out, stream: new(C.bz_stream)}
	C.BZ2_bzCompressInit(w.stream, blockSize, verbosity, workFactor)
	return w
}
Exemplo n.º 3
0
// NewWriter returns a writer for bzip2-compressed streams.
func NewWriter(out io.Writer) io.WriteCloser {
	const (
		blockSize  = 9
		verbosity  = 0
		workFactor = 30
	)
	// NOTE: This code may not work in future Go releases.
	// See http://www.gopl.io/errata.html for explanation.
	w := &writer{w: out, stream: new(C.bz_stream)}
	C.BZ2_bzCompressInit(w.stream, blockSize, verbosity, workFactor)
	return w
}
Exemplo n.º 4
0
// New bzip2 writer with a specific level and buffer size.
//
// The block size in 100ks must be between 1 and 9, just like with (lib)bzip2,
// and the buffer size should be a reasonable value for all intents and
// purposes.
func NewWriterLevelBufferSize(w io.Writer, blockSize100k int, bufferSize int) (Writer, error) {
	bw := &writer{
		w:         w,
		outBuffer: make([]byte, bufferSize),
	}

	// Initialize the compression stream.
	ret := C.BZ2_bzCompressInit(&bw.bzStream, C.int(blockSize100k), C.int(0), C.int(0))

	if err := translateError(ret); err != nil {
		return nil, err
	}

	return bw, nil
}