Skip to content

johnmarkli/timpalpant-gzran

 
 

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

Packages

No packages published

Languages

  • Go 100.0%