blast

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

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

Go to latest
Published: Aug 8, 2021 License: Zlib Imports: 4 Imported by: 11

README

blast Go Documentation Travis

Golang library for both compressing and decompressing data in the PKWare Data Compression Library (DCL) compressed format, otherwise known as "explode" and "implode" which differ from PKZIP.

Based on:

blast.c in ZLIB written by Mark Adler https://github.com/madler/zlib/blob/master/contrib/blast/blast.c

implode.c Ladislav Zezula 2003 https://github.com/ladislav-zezula/StormLib/blob/master/src/pklib/implode.c

Installation
go get github.com/JoshVarga/blast
Features
Compress ("implode") data using the PKWARE DCL "implode" method
Decompress ("explode") data that has been compressed using PKWARE DCL "implode" method
Example
func ExampleNewWriter() {
	var b bytes.Buffer
	w := blast.NewWriter(&b, blast.Binary, blast.DictionarySize1024)
	w.Write([]byte("AIAIAIAIAIAIA"))
	w.Close()
	fmt.Println(b.Bytes())
	// Output: [0 4 130 36 37 143 128 127]
}

func ExampleNewReader() {
	buff := []byte{0, 4, 130, 36, 37, 143, 128, 127}
	b := bytes.NewReader(buff)
	r, err := blast.NewReader(b)
	if err != nil {
		panic(err)
	}
	io.Copy(os.Stdout, r)
	// Output: AIAIAIAIAIAIA
	r.Close()
}
License

Copyright (c) 2018 Josh Varga

Explode: Original C version: Copyright (C) 2003, 2012, 2013 Mark Adler, version 1.3, 24 Aug 2013

Implode: Original C version: Copyright (c) Ladislav Zezula 2003

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

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

View Source
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

View Source
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")
)
View Source
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 Crc32

func Crc32(buffer []byte, oldCrc uint32) uint32

Crc32 returns the 32-bit CRC (Cyclic Redundancy Check) value for the given buffer

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

func NewWriter(w io.Writer, implodeType uint, dictSize uint) *Writer

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]

func (*Writer) Close

func (w *Writer) Close() error

Close flushes and closes the writer.

func (*Writer) Write

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

Write writes a compressed form of p to the underlying io.Writer. The compressed bytes are not necessarily flushed until the Writer is closed.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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