Documentation ¶
Overview ¶
Package blast implements reading of PKWare Data Compression Library (DCL) compressed data, otherwise known as "explode" for "imploded" data
The implementation provides functionality that decompresses during reading.
For example, to read compressed data from a buffer:
r, err := blast.NewReader(&b) io.Copy(os.Stdout, r) r.Close()
Index ¶
Examples ¶
Constants ¶
const ( // Binary represents the Binary compression mode Binary = 0 // ASCII represents the ASCII compression mode ASCII = 1 // DictionarySize1024 represents a dictiony of size 1024 is used DictionarySize1024 = 1024 // DictionarySize2048 represents a dictiony of size 2048 is used DictionarySize2048 = 2048 // DictionarySize4096 represents a dictiony of size 4096 is used DictionarySize4096 = 4096 )
Variables ¶
var ( // ErrHeader is returned when reading data that has an invalid header. ErrHeader = errors.New("blast: invalid header") // ErrDictionary is returned when reading data that has an invalid dictionary. ErrDictionary = errors.New("blast: invalid dictionary") // ErrDistanceTooFar is returned when reading data that has an invalid repetition length. ErrDistanceTooFar = errors.New("distance is too far back") // ErrUnexpectedEOF means that EOF was encountered ErrUnexpectedEOF = errors.New("unexpected EOF") )
var ( // ErrInvalidDictSize is returned when writing data and an invalid dictionary size is specified. ErrInvalidDictSize = errors.New("blast: invalid dictionary size") // ErrInvalidMode is returned when writing data and an invalid implode mode was given. ErrInvalidMode = errors.New("blast: invalid implode mode") )
Functions ¶
func NewReader ¶
func NewReader(r io.Reader) (io.ReadCloser, error)
NewReader creates a new ReadCloser. Reads from the returned ReadCloser read and decompress data from r. It is the caller's responsibility to call Close on the ReadCloser when done.
Example ¶
package main import ( "bytes" "io" "os" "github.com/JoshVarga/blast" ) func main() { buff := []byte{0, 4, 130, 36, 37, 143, 128, 127} b := bytes.NewReader(buff) r, err := blast.NewReader(b) if err != nil { panic(err) } _, err = io.Copy(os.Stdout, r) if err != nil { } err = r.Close() if err != nil { } }
Output: AIAIAIAIAIAIA
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer takes data written to it and writes the compressed form of that data to an underlying writer (see NewWriter).
func NewWriter ¶
NewWriter creates a new Writer. Writes to the returned Writer are compressed and written to w.
It is the caller's responsibility to call Close on the WriteCloser when done. Writes may be buffered and not flushed until Close.
Example ¶
package main import ( "bytes" "fmt" "github.com/JoshVarga/blast" ) func main() { var b bytes.Buffer w := blast.NewWriter(&b, blast.Binary, blast.DictionarySize1024) count, err := w.Write([]byte("AIAIAIAIAIAIA")) if err != nil { fmt.Print("failed to write") } if count != 13 { fmt.Printf("incorrect number of bytes written: %v", count) } err = w.Close() fmt.Print(b.Bytes()) if err != nil { } }
Output: [0 4 130 36 37 143 128 127]