Skip to content
forked from timpalpant/gzran

gzip indexer for random access into compressed files

License

Notifications You must be signed in to change notification settings

prequel-dev/gzran

This branch is up to date with timpalpant/gzran:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7b631e5 · Nov 27, 2020

History

18 Commits
Nov 27, 2020
Nov 1, 2020
Nov 27, 2020
Nov 25, 2020
Nov 25, 2020
Nov 26, 2020
Nov 25, 2020
Nov 27, 2020
Nov 27, 2020
Nov 26, 2020
Nov 27, 2020

Repository files navigation

gzran

GoDoc Build Status Coverage Status Go Report Card

Package gzran reads arbitrary offsets of uncompresssed data from compressed gzip files. This is accomplished by saving decompressor state periodically as the Reader progresses on the fly. The built Index can then be used to seek back to points within the file efficiently, or serialized and then used later.

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

Example

gzr, _ := gzran.NewReader(r)
// Seek forward within the file, building index as we go.
if _, err := gzr.Seek(n, io.SeekStart); err != nil {
  panic(err)
}
// Seek backward, using the on-the-fly index to do so efficiently.
if _, err := gzr.Seek(n - 128000, io.SeekStart); err != nil {
  panic(err)
}

// Read through entire file to index it, and then save the Index to a file.
if _, err := io.Copy(ioutil.Discard, gzr); err != nil {
  panic(err)
}
if err := gzr.Index.WriteTo(f); err != nil {
  panic(err)
}

// Create a new gzip.Reader and load the Index to use it.
gzr, _ := gzran.NewReader(r)
gzr.Index, _ = gzran.LoadIndex(f)
// Seek and read as desired using the Index.

About

gzip indexer for random access into compressed files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%