smaz

package module
v0.0.0-...-d41de67 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2018 License: MIT Imports: 2 Imported by: 0

README

This is a pure Go implementation of antirez's SMAZ, a library for compressing short, English strings (it won't work well for other languages).

Installation

$ go get github.com/kjk/smaz

Usage

import (
  "github.com/kjk/smaz"
)

func main() {
  s := "Now is the time for all good men to come to the aid of the party."
  compressed := smaz.Encode(nil, []byte(s))
  decompressed, err := smaz.Decode(nil, compressed)
  if err != nil {
    fmt.Printf("decompressed: %s\n", string(decompressed))
    ...
}

Full API documentation.

Notes

This is not a direct port of the C version. It is not guaranteed that the output of smaz.Encode 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.Decode.

Author

Salvatore Sanfilippo designed SMAZ and wrote [C implementation]](https://github.com/antirez/smaz).

Caleb Spare wrote initial Go port.

Krzysztof Kowalczyk improved speed of decompression (2.4x faster) and compression (1.3x faster).

Contributors

Antoine Grondin

License

MIT Licensed.

Other implementations

Documentation

Overview

Package smaz is a pure Go implementation of the smaz algorithm (https://github.com/antirez/smaz) for compressing small strings.

Index

Constants

This section is empty.

Variables

View Source
var DefaultCodec = NewCodec(DefaultCodeStrings())
View Source
var ErrCorrupt = errors.New("smaz: corrupt input")

ErrCorrupt reports that the input is invalid.

Functions

func DefaultCodeStrings

func DefaultCodeStrings() []string

Types

type Codec

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

func NewCodec

func NewCodec(table []string) *Codec

func (*Codec) Decode

func (cdc *Codec) Decode(dst, src []byte) ([]byte, error)

Decode returns the decoded form of src. The returned slice may be a sub-slice of dst if dst was large enough to hold the entire decoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil dst.

func (*Codec) Encode

func (cdc *Codec) Encode(dst, src []byte) []byte

Encode returns the encoded form of src. The returned slice may be a sub-slice of dst if dst was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. It is valid to pass a nil dst.

Directories

Path Synopsis
Package trie is an implementation of a trie (prefix tree) data structure mapping []bytes to ints.
Package trie is an implementation of a trie (prefix tree) data structure mapping []bytes to ints.

Jump to

Keyboard shortcuts

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