lzhuf

package
v0.11.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package lzhuf implements the lzhuf compression used by the binary FBB protocols B, B1 and B2.

The compression is LZHUF with a CRC16 checksum of the compressed data prepended (B2F option).

Index

Constants

This section is empty.

Variables

View Source
var ErrChecksum = errors.New("lzhuf: invalid checksum")

ErrChecksum indicates a checksum or file size mismatch on decode.

Functions

This section is empty.

Types

type Reader added in v0.7.0

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

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

Lzhuf files store a length and optionally a checksum of the uncompressed data. The Reader will return io.ErrUnexpectedEOF when Read reaches the end of the uncompressed data. The checksum is verified on Close.

Clients should treat data returned by Read as tentative until they receive the io.EOF marking the end of the data. Data consistency should then be verified by calling Close.

func NewB2Reader added in v0.7.0

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

NewB2Reader creates a new Reader expecting the extended FBB B2 format used by Winlink.

It is the caller's responsibility to call Close on the Reader when done.

func NewReader added in v0.7.0

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

NewReader creates a new Reader reading the given reader.

If crc16 is true, the Reader will expect and verify a checksum of the compressed data (as per FBB B2).

It is the caller's responsibility to call Close on the Reader when done.

func (*Reader) Close added in v0.7.0

func (d *Reader) Close() error

Close closes the Reader. It does not close the underlying io.Reader.

If an error was encountered during Read, the error will be returned. ErrChecksum is returned if the filesize header does not match the number of bytes read, or a crc16 checksum (B2 format) was expected but did not match.

If no error is returned, the file has been successfully decompressed.

func (*Reader) Read added in v0.7.0

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

Read reads uncompressed data into p. It returns the number of bytes read into p.

At EOF, count is 0 and err is io.EOF (unless len(p) is zero).

type Writer added in v0.7.0

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

A Writer is an io.WriteCloser. Writes to a Writer are compressed and writter to w.

func NewB2Writer added in v0.7.0

func NewB2Writer(w io.Writer) *Writer

NewB2Writer returns a new Writer with the extended FBB B2 format used by Winlink.

It is the caller's responsibility to call Close on the WriteCloser when done. Writes may be buffered and not flushed until Close.

func NewWriter added in v0.7.0

func NewWriter(w io.Writer, crc16 bool) *Writer

NewWriter returns a new Writer. Writes to the returned writer are compressed and written to w.

If crc16 is true, the header will be prepended with a checksum of the compressed data (as per FBB B2).

It is the caller's responsibility to call Close on the WriteCloser when done. Writes may be buffered and not flushed until Close.

func (*Writer) Close added in v0.7.0

func (w *Writer) Close() error

Close closes the Writer, flushing any unwritten data to the underlying io.Writer, but does not close the underlying io.Writer.

func (*Writer) Write added in v0.7.0

func (w *Writer) Write(p []byte) (n int, err error)

Write writes a compressed form of p to the underlying io.Writer. The compressed bytes are not necessarily flushed until the Writer is closed.

Jump to

Keyboard shortcuts

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