Пример #1
0
// Reset discards the state of Writer and makes it equivalent
// to the result of NewWriter or NewWriterLevel, but writing
// to dst instead.
func (w *Writer) Reset(dst io.Writer) {
	w.bw = bits.NewWriter(dst)
	w.block = newBlock(w.block.size)
	w.crc = 0
	w.wroteHeader = false
	w.closed = false
	w.err = nil
}
Пример #2
0
// NewWriterLevel is like NewWriter but specifies the
// compression level.
//
// The levels range from 1 (BestSpeed) to 9 (BestCompression);
// higher levels typically run slower but compress more.
//
// If level is in the range [1, 9] then the error returned will
// be nil. Otherwise the error returned will be non-nil.
func NewWriterLevel(w io.Writer, level int) (*Writer, error) {
	if level < BestSpeed || level > BestCompression {
		return nil, fmt.Errorf("bzip2: invalid compression level: %d", level)
	}

	return &Writer{
		bw:    bits.NewWriter(w),
		block: newBlock(level * baseBlockSize),
	}, nil
}
Пример #3
0
// NewWriter returns a new Writer. Writes to the returned
// writer are compressed and written to w.
//
// It is the caller's responsibility to call Close on the
// Writer when done. Writes may be buffered and not
// flushed until Close.
func NewWriter(w io.Writer) *Writer {
	return &Writer{
		bw:    bits.NewWriter(w),
		block: newBlock(6 * baseBlockSize),
	}
}