xzwriter

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

xzwriter: a trivial Go library for compressing with XZ.

Apache License v2.0 GoDoc

Package xzwriter provides a writer XZWriter that pipes through an external XZ compressor.

Expects the Tukaani XZ tool in $PATH. See the XZ Utils home page: http://tukaani.org/xz/

License

As this is a trivial convenience package, you should probably not import this. Anyway licensed under the Apache License, Version 2.0.

See also

https://github.com/ulikunitz/xz

Documentation

Overview

Package xzwriter provides a WriteCloser XZWriter that pipes through an external XZ compressor.

Expects the Tukaani XZ tool in $PATH. See the XZ Utils home page: <http://tukaani.org/xz/>

Index

Constants

View Source
const (
	Fast    = 0
	Default = 6
	Best    = 9
)

Variables

View Source
var (
	ErrOptionIllegal = errors.New("option illegal")
)

Functions

This section is empty.

Types

type Option added in v0.1.2

type Option func(*XZWriter) error

func WithCompressLevel added in v0.1.2

func WithCompressLevel(l int) Option

WithCompressLevel sets the compression level between 0 and 9. The constants `Fast`, `Default` and `Best` correspond to the flags `--fast`, `--default` and `--best`.

func WithExtreme added in v0.1.2

func WithExtreme() Option

WithExtreme set the `--extreme` flag.

func WithSeparateProcessGroup added in v0.1.2

func WithSeparateProcessGroup() Option

WithSeparateProcessGroup set's the process group of the `xz` subprocess to its own, separate process group. When the program using this library is started in a shell session, hitting CTRL+C will send an interrupt signal to both processes. That means that the `xz` process terminates immediately without reading STDIN to its end, instead writes to the xzwriter fails with ERRPIPE.

If the program using this library wants to handle the SIGINT gracefully, one needs to prevent the shell from sending the SIGINT to the xz subprocess also. Running `xz` in a separate process group achieves that.

func WithVerbose added in v0.1.2

func WithVerbose(stderr io.Writer) Option

WithVerbose sets verbosity and takes a writer that will be connected to STDERR of the xz subprocess. This provides a nice progress output to look at.

type XZWriter

type XZWriter struct {
	// contains filtered or unexported fields
}

XZWriter is a WriteCloser that wraps a writer around an XZ compressor.

func New

func New(w io.Writer) (*XZWriter, error)

New returns an XZWriter, wrapping the writer w.

func NewWithContext

func NewWithContext(ctx context.Context, w io.Writer) (*XZWriter, error)

NewWithContext returns an XZWriter, wrapping the writer w. The context may be used to cancel or timeout the external compressor process.

The context can be used to kill the external process early. You still need to call Close() to clean up ressources. Alternatively you may call Close() prematurely.

func NewWithOptions added in v0.1.2

func NewWithOptions(ctx context.Context, w io.Writer, opts ...Option) (*XZWriter, error)

NewWithOptions returns an XZWriter, wrapping the writer w. The context may be used to cancel or timeout the external compressor process.

The context can be used to kill the external process early. You still need to call Close() to clean up ressources. Alternatively you may call Close() prematurely.

The compressor process can be configured with options.

func (*XZWriter) Close

func (xz *XZWriter) Close() error

Close implements the io.Closer interface.

func (*XZWriter) Write

func (xz *XZWriter) Write(p []byte) (n int, err error)

Write implements the io.Writer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL