smaz

package module
v0.0.0-...-7c47968 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: MIT Imports: 1 Imported by: 0

README

go-smaz

GoDoc

go-smaz is a pure Go implementation of antirez's smaz, a library for compressing short strings (particularly containing English words).

Installation

$ go get github.com/cespare/go-smaz

Usage

import (
  "github.com/cespare/go-smaz"
)

func main() {
  s := "Now is the time for all good men to come to the aid of the party."
  compressed := smaz.Compress([]byte(s))           // type is []byte
  decompressed, err := smaz.Decompress(compressed) // type is []byte; string(decompressed) == s
  if err != nil {
    ...
}

Also see the API documentation.

Notes

go-smaz is not a direct port of the C version. It is not guaranteed that the output of smaz.Compress will be precisely the same as the C library. However, the output should be decompressible by the C library, and the output of the C library should be decompressible by smaz.Decompress.

Author

Caleb Spare (cespare). smaz was created by Salvatore Sanfilippo (antirez).

Contributors

License

MIT Licensed.

Other implementations

Documentation

Overview

Package smaz is an implementation of the smaz library for compressing small strings.

Index

Constants

This section is empty.

Variables

Default use the library for the default dictionary

View Source
var (
	DefaultDict = []string{}/* 254 elements not displayed */

)
View Source
var ErrDecompression = errors.New("invalid or corrupted compressed data")

ErrDecompression is returned when decompressing invalid smaz-encoded data.

Functions

func Compress

func Compress(input []byte) []byte

Compress compresses a byte slice and returns the compressed data.

func Decompress

func Decompress(b []byte) ([]byte, error)

Decompress decompresses a smaz-compressed byte slice and return a new slice with the decompressed data. err is nil if and only if decompression fails for any reason (e.g., corrupted data).

Types

type Smaz

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

Smaz Is an implementation of Smaz compression

func NewSmaz

func NewSmaz(dict []string) *Smaz

func (*Smaz) Compress

func (s *Smaz) Compress(input []byte) []byte

Compress compresses a byte slice and returns the compressed data.

func (*Smaz) Decompress

func (s *Smaz) Decompress(b []byte) ([]byte, error)

Decompress decompresses a smaz-compressed byte slice and return a new slice with the decompressed data. err is nil if and only if decompression fails for any reason (e.g., corrupted data).

Jump to

Keyboard shortcuts

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