lzip

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: Apache-2.0, MIT Imports: 8 Imported by: 0

README

lzip-go

CI Go Reference Go version

lzip-go is an implementation of the lzip compressed format written in pure Go.

This package supports reading and writing of lzip compressed streams.

Usage

To install this package:

go get -u github.com/sorairolake/lzip-go
Example

Please see example_test.go.

Documentation

See the documentation for more details.

Command-line utility

This package includes a simple command-line utility for reading and writing of lzip format compressed files.

To install:

go install github.com/sorairolake/lzip-go/cmd/glzip@latest

See glzip(1) for details.

Minimum Go version

This package requires the minimum version of Go 1.22.

Changelog

Please see CHANGELOG.adoc.

Contributing

Please see CONTRIBUTING.adoc.

Acknowledgment

The API of this package is based on the compress/gzip package.

This package uses the github.com/ulikunitz/xz/lzma package to encode and decode LZMA streams.

License

Copyright © 2024 Shun Sakai (see AUTHORS.adoc)

This package is distributed under the terms of either the Apache License 2.0 or the MIT License.

This project is compliant with version 3.0 of the REUSE Specification. See copyright notices of individual files for more details on copyright and licensing information.

Documentation

Overview

Package lzip implements reading and writing of lzip format compressed files. The package supports version 1 of the specification.

See the following for the specification:

Example
const text = "The quick brown fox jumps over the lazy dog."

opt := &lzip.WriterOptions{4 * 1024 * 1024}

var buf bytes.Buffer

writer, err := lzip.NewWriterOptions(&buf, opt)
if err != nil {
	log.Fatal(err)
}

if _, err := io.WriteString(writer, text); err != nil {
	log.Fatal(err)
}

if err := writer.Close(); err != nil {
	log.Fatal(err)
}

reader, err := lzip.NewReader(&buf)
if err != nil {
	log.Fatal(err)
}

if _, err := io.Copy(os.Stdout, reader); err != nil {
	log.Fatal(err)
}
Output:

The quick brown fox jumps over the lazy dog.

Index

Examples

Constants

View Source
const (
	// MinDictSize is the minimum dictionary size, which is 4 KiB.
	MinDictSize = lzma.MinDictCap

	// MaxDictSize is the maximum dictionary size, which is 512 MiB.
	MaxDictSize = 1 << 29

	// DefaultDictSize is the default dictionary size, which is 8 MiB.
	DefaultDictSize = 1 << 23
)
View Source
const MaxMemberSize = 1 << 51

MaxMemberSize is the maximum member size, which is 2 PiB.

Variables

View Source
var ErrInvalidMagic = errors.New("lzip: invalid magic number")

ErrInvalidMagic represents an error due to the magic number was invalid.

Functions

This section is empty.

Types

type DictSizeTooLargeError

type DictSizeTooLargeError struct {
	// DictSize represents the obtained dictionary size.
	DictSize uint32
}

DictSizeTooLargeError represents an error due to the dictionary size was larger than 512 MiB.

func (*DictSizeTooLargeError) Error

func (e *DictSizeTooLargeError) Error() string

Error returns a string representation of a DictSizeTooLargeError.

type DictSizeTooSmallError

type DictSizeTooSmallError struct {
	// DictSize represents the obtained dictionary size.
	DictSize uint32
}

DictSizeTooSmallError represents an error due to the dictionary size was smaller than 4 KiB.

func (*DictSizeTooSmallError) Error

func (e *DictSizeTooSmallError) Error() string

Error returns a string representation of a DictSizeTooSmallError.

type InvalidCRCError

type InvalidCRCError struct {
	// CRC represents the obtained CRC.
	CRC uint32
}

InvalidCRCError represents an error due to a CRC of the original uncompressed data mismatched.

func (*InvalidCRCError) Error

func (e *InvalidCRCError) Error() string

Error returns a string representation of an InvalidCRCError.

type InvalidDataSizeError

type InvalidDataSizeError struct {
	// DataSize represents the obtained data size.
	DataSize uint64
}

InvalidDataSizeError represents an error due to the size of the original uncompressed data stored in the trailer and the actual size of it mismatched.

func (*InvalidDataSizeError) Error

func (e *InvalidDataSizeError) Error() string

Error returns a string representation of an InvalidDataSizeError.

type InvalidMemberSizeError

type InvalidMemberSizeError struct {
	// MemberSize represents the obtained member size.
	MemberSize uint64
}

InvalidMemberSizeError represents an error due to the total size of the member stored in the trailer and the actual total size of it mismatched.

func (*InvalidMemberSizeError) Error

func (e *InvalidMemberSizeError) Error() string

Error returns a string representation of an InvalidMemberSizeError.

type MemberSizeTooLargeError

type MemberSizeTooLargeError struct {
	// MemberSize represents the obtained member size.
	MemberSize uint64
}

MemberSizeTooLargeError represents an error due to the member size was larger than 2 PiB.

func (*MemberSizeTooLargeError) Error

func (e *MemberSizeTooLargeError) Error() string

Error returns a string representation of a MemberSizeTooLargeError.

type Reader

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

Reader is an io.Reader that can be read to retrieve uncompressed data from a lzip-format compressed file.

Example
file, err := os.Open("testdata/fox.lz")
if err != nil {
	log.Fatal(err)
}
defer file.Close()

reader, err := lzip.NewReader(bufio.NewReader(file))
if err != nil {
	log.Print(err)

	return
}

if _, err := io.Copy(os.Stdout, reader); err != nil {
	log.Print(err)

	return
}
Output:

The quick brown fox jumps over the lazy dog.

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader creates a new Reader reading the given reader.

func (*Reader) Read

func (z *Reader) Read(p []byte) (n int, err error)

Read reads uncompressed data from the stream.

type UnknownVersionError

type UnknownVersionError struct {
	// Version represents the obtained version number.
	Version uint8
}

UnknownVersionError represents an error due to the version number stored in the header was not recognized by this package.

func (*UnknownVersionError) Error

func (e *UnknownVersionError) Error() string

Error returns a string representation of an UnknownVersionError.

type UnsupportedVersionError

type UnsupportedVersionError struct {
	// Version represents the obtained version number.
	Version uint8
}

UnsupportedVersionError represents an error due to the version number stored in the header indicated the lzip format which is not supported by this package.

func (*UnsupportedVersionError) Error

func (e *UnsupportedVersionError) Error() string

Error returns a string representation of an UnsupportedVersionError.

type Writer

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

Writer is an io.WriteCloser that can be written to retrieve a lzip-format compressed file from data.

Example
const text = "The quick brown fox jumps over the lazy dog."

var buf bytes.Buffer
writer := lzip.NewWriter(&buf)

if _, err := io.WriteString(writer, text); err != nil {
	log.Fatal(err)
}

if err := writer.Close(); err != nil {
	log.Fatal(err)
}
Output:

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a new Writer writing the given writer.

This uses the default parameters.

func NewWriterOptions

func NewWriterOptions(w io.Writer, opt *WriterOptions) (*Writer, error)

NewWriterOptions creates a new Writer writing the given writer.

This uses the given WriterOptions.

func (*Writer) Close

func (z *Writer) Close() error

Close closes the Writer and writing the lzip trailer. It does not close the underlying io.Writer.

func (*Writer) Write

func (z *Writer) Write(p []byte) (int, error)

Write compresses the given uncompressed data.

type WriterOptions

type WriterOptions struct {
	// DictSize sets the dictionary size.
	DictSize uint32
}

WriterOptions configures Writer.

func (*WriterOptions) Verify

func (o *WriterOptions) Verify() error

Verify checks if WriterOptions is valid.

Directories

Path Synopsis
cmd
glzip
Glzip reduces the size of files.
Glzip reduces the size of files.

Jump to

Keyboard shortcuts

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