compress

package
v0.0.0-...-015e77e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeFormat

func EncodeFormat(data []byte, f Format) []byte

EncodeFormat adds the compression format to the compressed data.

Types

type CompressorFunc

type CompressorFunc func(data []byte) (compressed []byte, err error)

CompressorFunc is the function the prototype for compression.

var PassthroughCompressor CompressorFunc = func(data []byte) ([]byte, error) {
	return []byte(hex.EncodeToString(data)), nil
}

PassthroughCompressor is a dummy function for development and testing *ONLY*.

* WARNING: DO NOT USE IN PRODUCTION. * PassthroughCompressor is *NOT* compression and *DOES NOT* compress data.

type DecompressorFunc

type DecompressorFunc func(compressed []byte) (data []byte, err error)

DecompressorFunc is the function the prototype for decompression.

var PassthroughDecompressor DecompressorFunc = func(compressed []byte) ([]byte, error) {
	return hex.DecodeString(string(compressed))
}

PassthroughDecompressor is a dummy function for development and testing *ONLY*.

* WARNING: DO NOT USE IN PRODUCTION. * PassthroughDecompressor is *NOT* decompression and *DOES NOT* decompress data.

type Format

type Format string

Format is the supporter compression algorithm type.

const (
	// None no compression.
	None Format = ""

	// Custom a custom compression format is being used.
	Custom Format = "custom"

	// Zstd Zstandard compression https://facebook.github.io/zstd/.
	Zstd Format = "zstd"
)

TODO: support additional compression algorithms besides

Zstandard from https://github.com/klauspost/compress

func DecodeFormat

func DecodeFormat(data []byte) ([]byte, Format)

DecodeFormat removes and returns the compression format from the compressed data. If no compression format is found DecodeFormat returns the original the data.

func (Format) Valid

func (f Format) Valid() bool

Valid returns true if the Format is valid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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