gobzip

package module
v0.0.0-...-6428c5b Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: Apache-2.0 Imports: 9 Imported by: 1

README

#gobzip

package gobzip uses cgo to wrap the bzlip to provide bzip compressor in golang. Because golang native library only provides bzip uncompressor (see http://golang.org/pkg/compress/bzip2/, they have a feature request for implementing bzip compressor, but haven't finished it yet. see the issue ticker here: https://code.google.com/p/go/issues/detail?id=4828). Thus BzipWriter is introduced.

####bzlib:

  1. make sure you have bzlib.h, if not, please build the source code from http://www.bzip.org
  2. we pushed built-in Darwin/Linux amd64 lib in bzip/lib. You can use them directly if you are one of them. add them into cgo NOTE: the part and the platform you used
export CGO_CFLAGS=-Ibzip/include
export CGO_LDFLAGS=-Lbzip/Darwin_amd64/lib/

import

go get github.com/hsinhoyeh/gobzip

example

    import (
        "github.com/hsihoyeh/gobzip"
    )

    func main(){

        buf := &bytes.Buffer{}
        w, _ := NewBzipWriter(cBuf)
        w.Write([]byte("I am a plain text message"))
        w.Close()
        fmt.Println(buf.Bytes())
    }

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStream     = errors.New("bzip: stream")
	ErrConfig     = errors.New("bzip: config")
	ErrSequence   = errors.New("bzip: sequence")
	ErrParam      = errors.New("bzip: parameter")
	ErrMem        = errors.New("bzip: memory")
	ErrData       = errors.New("bzip: data")
	ErrDataMagic  = errors.New("bzip: data magic")
	ErrIO         = errors.New("bzip: i/o")
	ErrUnexpected = errors.New("bzip: unexpected")
	ErrOutbufFull = errors.New("bzip: output buffer full")
	ErrUnknown    = errors.New("bzip: unknown error")
)

Functions

func BzipError

func BzipError(err int) error

BzipError converts the err codes into golang's error

Types

type BzipWriter

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

func NewBzipWriter

func NewBzipWriter(w io.Writer) (*BzipWriter, error)

NewBzipWriter returns a BzipWriter which compresses byte data to w

func (*BzipWriter) Close

func (b *BzipWriter) Close() error

Close closes the bzip writer and flushes the data to the w

func (*BzipWriter) Write

func (b *BzipWriter) Write(d []byte) (int, error)

Write writes the byte data to the bzip writer

Jump to

Keyboard shortcuts

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