compression

package
v0.0.0-...-429085d Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InvalidRLERun = ByteRun{0, 0}

InvalidRLERun is a sentinel value returned by RLEGrouper.GetNextRun if an error occurred, or EOF was encountered.

Functions

func CompressImage

func CompressImage(input io.Reader, output io.Writer) (int64, error)

CompressImage compresses a disk image using RLE8 and gzip.

The returned int64 gives the number of bytes written to the output stream. If an error occurred, this value is undefined and should not be used.

func CompressRLE8

func CompressRLE8(input io.Reader, output io.Writer) (int64, error)

CompressRLE8 reads bytes from the input and writes compressed data from the output until the input is exhausted. The return value is the number of bytes written, only valid if no error occurred.

func DecompressImage

func DecompressImage(input io.Reader, output io.Writer) (int64, error)

DecompressImage takes a gzipped, RLE8-encoded byte stream and decompresses it to the original data.

The returned int64 gives the number of bytes written to the output (i.e. the decompressed size of the data). If an error occurred, the value is undefined and should not be used.

func DecompressImageToBytes

func DecompressImageToBytes(input io.Reader) ([]byte, error)

DecompressImageToBytes is a convenience function wrapping DecompressImage. It functions identically, except it returns the decompressed data in a new byte slice instead of writing to an io.Writer. It's most useful for reading embedded test data.

func DecompressRLE8

func DecompressRLE8(input io.Reader, output io.Writer) (int64, error)

Types

type ByteRun

type ByteRun struct {
	// Byte is the byte value for this run.
	Byte byte
	// RunLength gives the number of times the byte occurs in the run.
	//
	// A valid run will always have this be 1 or greater. A value less than 1
	// indicates either EOF was encountered, or an error occurred.
	RunLength int
}

ByteRun represents a single run of a particular byte value.

type RLEGrouper

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

An RLEGrouper wraps an io.Reader and returns a ByteRun upon reads.

This functions much like the `uniq` command line utility.

func NewRLEGrouperFromByteScanner

func NewRLEGrouperFromByteScanner(rd io.ByteScanner) RLEGrouper

NewRLEGrouper constructs an RLEGrouper from an io.ByteScanner.

func NewRLEGrouperFromReader

func NewRLEGrouperFromReader(rd io.Reader) RLEGrouper

NewRLEGrouperFromReader constructs an RLEGrouper from an io.Reader.

func (RLEGrouper) GetNextRun

func (grouper RLEGrouper) GetNextRun() (ByteRun, error)

GetNextRun returns a ByteRun for the next byte or run of byte values in the stream. The length of a valid run is guaranteed to be in the range [1, math.MaxInt). A valid run will never have length 0.

The returned error behaves identically to io.Reader.Read, namely that if the returned run length is non-zero, the error will either be nil or io.EOF. If it's zero, the error is either io.EOF or another (non-nil) error.

Jump to

Keyboard shortcuts

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