snappy

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

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

Go to latest
Published: Nov 24, 2016 License: BSD-3-Clause Imports: 6 Imported by: 133

README

Snappy

This is a fork of the snappy-go library from code.google.com. It has been changed to use the C++ snappy library for encoding and decoding.

This package is also a go-gettable version of the C++ snappy library for use in Go code that needs to link against the C++ snappy library but wants to integrate with go get and go build. The snappy source is currently pinned to the 1.1.1 release.

To use in your project you need to import the package and set appropriate cgo flag directives:

import _ "github.com/cockroachdb/c-snappy"

// #cgo CXXFLAGS: -std=c++11
// #cgo CPPFLAGS: -I <relative-path>/c-snappy/internal
// #cgo darwin LDFLAGS: -Wl,-undefined -Wl,dynamic_lookup
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
import "C"

Documentation

Overview

Package snappy uses the cgo compilation facilities to build the Snappy C++ library.

Package snappy implements the snappy block-based compression format. It aims for very high speeds and reasonable compression.

The C++ snappy implementation is at http://code.google.com/p/snappy/

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCorrupt reports that the input is invalid.
	ErrCorrupt = errors.New("snappy: corrupt input")
	// ErrUnsupported reports that the input isn't supported.
	ErrUnsupported = errors.New("snappy: unsupported input")
)

Functions

func Decode

func 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 DecodedLen

func DecodedLen(src []byte) (int, error)

DecodedLen returns the length of the decoded block.

func Encode

func Encode(dst, src []byte) ([]byte, error)

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.

func MaxEncodedLen

func MaxEncodedLen(srcLen int) int

MaxEncodedLen returns the maximum length of a snappy block, given its uncompressed length.

Types

type Reader

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

Reader is an io.Reader than can read Snappy-compressed bytes.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a new Reader that decompresses from r, using the framing format described at https://code.google.com/p/snappy/source/browse/trunk/framing_format.txt

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read satisfies the io.Reader interface.

func (*Reader) Reset

func (r *Reader) Reset(reader io.Reader)

Reset discards any buffered data, resets all state, and switches the Snappy reader to read from r. This permits reusing a Reader rather than allocating a new one.

type Writer

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

Writer is an io.Writer than can write Snappy-compressed bytes.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a new Writer that compresses to w, using the framing format described at https://code.google.com/p/snappy/source/browse/trunk/framing_format.txt

func (*Writer) Reset

func (w *Writer) Reset(writer io.Writer)

Reset discards the writer's state and switches the Snappy writer to write to w. This permits reusing a Writer rather than allocating a new one.

func (*Writer) Write

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

Write satisfies the io.Writer interface.

Jump to

Keyboard shortcuts

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