Skip to content

Nodejs filehandle for reading bgzip+.gzi compressed files

License

Notifications You must be signed in to change notification settings

GMOD/bgzf-filehandle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bgzf-filehandle

NPM version Build Status Greenkeeper badge

Transparently read indexed block-gzipped (BGZF) files, such as those created by bgzip, using coordinates from the uncompressed file.

Also provides a unzip utility function that properly decompresses BGZF chunks in both node and the browser. Uses pako when running in the browser, native zlib when running in node.

Install

$ npm install --save @gmod/bgzf-filehandle

Usage

const { BgzfFilehandle, unzip } = require('@gmod/bgzf-filehandle')

const f = new BgzfFilehandle({path: 'path/to/my_file.gz'})
// assumes a .gzi index exists at path/to/my_file.gz.gzi. can also
// pass `gziPath` to set it explicitly. Can also pass filehandles
// for the files: `filehandle` and `gziFilehandle`

// supports a subset of the NodeJS v10 filehandle API. currently
// just read() and stat()
const myBuf = Buffer.alloc(300)
await f.read(myBuf, 0, 300, 23234)
// now use the data in the buffer

const { size } = f.stat() // stat gives the size as if the file were uncompressed

// unzip takes a buffer and returns a promise for a new buffer
const chunkDataBuffer = readDirectlyFromFile(someFile, 123, 456)
const unzippedBuffer = await unzip(chunkDataBuffer)

Academic Use

This package was written with funding from the NHGRI as part of the JBrowse project. If you use it in an academic project that you publish, please cite the most recent JBrowse paper, which will be linked from jbrowse.org.

License

MIT © Robert Buels

About

Nodejs filehandle for reading bgzip+.gzi compressed files

Resources

License

Stars

Watchers

Forks

Packages

No packages published