bgzf

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package bgzf provides functions for reading and writing files in the BGZF compression format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	bytes.Buffer // cap == 2^16
}

Block represents a single BGZF block stores as a bytes.Buffer initialized to have a capacity of 65536 (max uint16).

func NewBlock

func NewBlock() *Block

NewBlock returns a pointer to a bytes buffer with capacity 65536.

type BlockReader

type BlockReader struct {
	// contains filtered or unexported fields
}

BlockReader is the decompressor for BGZF files which is at its core a gzip reader. The BGZF reader retains a *os.File to use for seek functionality as well as a *bufio.Reader to implement the io.ByteReader interface, required for reading gzip files as independent concatenated blocks, rather than a multistream.

func NewBlockReader

func NewBlockReader(filename string) *BlockReader

NewBlockReader opens a new BGZF reader for the input file.

func (*BlockReader) Close

func (r *BlockReader) Close() error

Close the file and gzip reader.

func (*BlockReader) ReadBlock

func (r *BlockReader) ReadBlock(b *Block) error

ReadBlock reads the next block into the input Block. Returns io.EOF at the end of the file.

func (*BlockReader) Seek

func (r *BlockReader) Seek(offset int64, whence int) (ret int64, err error)

Seek moves the reader to the beginning of the block denoted by the input offset. A subsequent call to ReadBlock will read the Seeked block. The whence input can be io.SeekStart, io.SeekCurrent, or io.SeekEnd.

type BlockWriter

type BlockWriter struct {
	// contains filtered or unexported fields
}

BlockWriter moves data -> compressor -> zipBlock -> file writer.

func NewBlockWriter

func NewBlockWriter(w io.Writer) *BlockWriter

NewBlockWriter creates a bgzf writer from any input writer.

func (*BlockWriter) Close

func (w *BlockWriter) Close() error

Close bgzf writer and add the magic EOF marker to the end of the file.

func (*BlockWriter) Write

func (w *BlockWriter) Write(p []byte) (n int, err error)

Write input bytes as a single bgzf block.

type Offset

type Offset struct {
	Compressed   int64  // offset in compressed file
	Uncompressed uint16 // offset in uncompressed block
}

Offset for a location in the BGZF file consisting of the compressed offset (the number of bytes before the beginning of the desired block starting from the beginning of the file), and and the uncompressed offset (the number of bytes from the desired record starting from the beginning of the uncompressed block).

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Read wraps a BlockReader and provides the Next and Read functions that automatically read a new block when the previous block has been completely read.

func NewReader

func NewReader(filename string) *Reader

NewReader opens a new BGZF reader that reads bytes instead of blocks.

func (*Reader) Close

func (r *Reader) Close() error

Close the file and gzip reader.

func (*Reader) Next

func (r *Reader) Next(n int) []byte

Next returns the next n bytes from the bgzf block. Next handles reading new block if more bytes are requested than are in the currently store block.

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

Read retrieves the next len(b) bytes from the reader and automatically handles block reading.

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (ret int64, err error)

Seek wraps the Seek function for BlockReader and resets the reader buffer.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a bgzf writer that writes bytes instead of blocks.

func (*Writer) Close

func (w *Writer) Close() error

Close bgzf writer and add the magic EOF marker to the end of the file.

func (*Writer) Write

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

Write writes any number of bytes to a buffer then writes the buffer as a block once 64KB of bytes have been stored.

Jump to

Keyboard shortcuts

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