gzran

package module
v0.0.0-...-06baa6d Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

README

gzran

Gzran is a package that reads arbitrary offsets of uncompresssed data from compressed gzip files. This is accomplished by first inflating a file and saving decompressor state into memory. Then, the built index can be used with the Extract function to read from the compressed file without fully inflating the file.

Gzran is based on the c library, zran, by Mark Adler: https://github.com/madler/zlib/blob/master/examples/zran.c

example

idx, err := gzran.BuildIndex(gzippedFileName)
if err != nil {
    panic(err)
}
b, err := gzran.Extract(gzippedFileName, idx, fileOffset, readLength)
if err != nil && err != io.EOF {
    panic(err)
}

Documentation

Overview

Package gzran is a go implementation of zran by Mark Adler: https://github.com/madler/zlib/blob/master/examples/zran.c Gzran indexes a gzip file with access points about every span bytes into the uncompressed output. The compressed file can be read from randomly once an index has been built, having to decompress on the average SPAN/2 uncompressed bytes before getting to the desired block of data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Extract

func Extract(filename string, idx Index, offset int64, length int64) ([]byte, error)

Extract uses an Index to read length bytes from offset into uncompressed data. If data is requested past the end of the uncompressed data, Extract will read less bytes then length and return io.EOF. Offset is zero indexed.

Types

type Index

type Index []*point

Index stores access points into compressed file. Span will determine the balance between the speed of random access against the memory requirements of the index.

func BuildIndex

func BuildIndex(file string) (Index, error)

BuildIndex decompresses given file and builds an index that records the state of the gzip decompresser every span bytes into the uncompressed data. This index can be used to randomly read uncompressed data from the compressed file. Data after the end of the first gzip stream in the file is ignored and so concatenated gzip files are not supported.

Directories

Path Synopsis
Package flate implements the DEFLATE compressed data format, described in RFC 1951.
Package flate implements the DEFLATE compressed data format, described in RFC 1951.
Package gzip implements reading and writing of gzip format compressed files, as specified in RFC 1952.
Package gzip implements reading and writing of gzip format compressed files, as specified in RFC 1952.

Jump to

Keyboard shortcuts

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