#include <stdint.h>
#include <stdio.h>
#include <zlib.h>
#include <sys/types.h>
Go to the source code of this file.
|
BGZF * | bgzf_dopen (int fd, const char *mode) |
|
BGZF * | bgzf_open (const char *path, const char *mode) |
|
BGZF * | bgzf_hopen (struct hFILE *fp, const char *mode) |
|
int | bgzf_close (BGZF *fp) |
|
ssize_t | bgzf_read (BGZF *fp, void *data, size_t length) |
|
ssize_t | bgzf_write (BGZF *fp, const void *data, size_t length) |
|
ssize_t | bgzf_raw_read (BGZF *fp, void *data, size_t length) |
|
ssize_t | bgzf_raw_write (BGZF *fp, const void *data, size_t length) |
|
int | bgzf_flush (BGZF *fp) |
|
int64_t | bgzf_seek (BGZF *fp, int64_t pos, int whence) |
|
int | bgzf_check_EOF (BGZF *fp) |
|
int | bgzf_is_bgzf (const char *fn) |
|
void | bgzf_set_cache_size (BGZF *fp, int size) |
|
int | bgzf_flush_try (BGZF *fp, ssize_t size) |
|
int | bgzf_getc (BGZF *fp) |
|
int | bgzf_getline (BGZF *fp, int delim, kstring_t *str) |
|
int | bgzf_read_block (BGZF *fp) |
|
int | bgzf_mt (BGZF *fp, int n_threads, int n_sub_blks) |
|
int | bgzf_useek (BGZF *fp, long uoffset, int where) |
|
long | bgzf_utell (BGZF *fp) |
|
int | bgzf_index_build_init (BGZF *fp) |
|
int | bgzf_index_load (BGZF *fp, const char *bname, const char *suffix) |
|
int | bgzf_index_dump (BGZF *fp, const char *bname, const char *suffix) |
|
#define BGZF_BLOCK_SIZE 0xff00 |
#define BGZF_ERR_HEADER 2 |
#define BGZF_ERR_MISUSE 8 |
#define BGZF_MAX_BLOCK_SIZE 0x10000 |
#define bgzf_tell |
( |
|
fp | ) |
(((fp)->block_address << 16) | ((fp)->block_offset & 0xFFFF)) |
Return a virtual file pointer to the current location in the file. No interpetation of the value should be made, other than a subsequent call to bgzf_seek can be used to position the file at the same point. Return value is non-negative on success.
int bgzf_check_EOF |
( |
BGZF * |
fp | ) |
|
Check if the BGZF end-of-file (EOF) marker is present
- Parameters
-
fp | BGZF file handler opened for reading |
- Returns
- 1 if the EOF marker is present and correct; 2 if it can't be checked, e.g., because fp isn't seekable; 0 if the EOF marker is absent; -1 (with errno set) on error
int bgzf_close |
( |
BGZF * |
fp | ) |
|
Close the BGZF and free all associated resources.
- Parameters
-
- Returns
- 0 on success and -1 on error
BGZF* bgzf_dopen |
( |
int |
fd, |
|
|
const char * |
mode |
|
) |
| |
Open an existing file descriptor for reading or writing.
- Parameters
-
fd | file descriptor |
mode | mode matching /[rwag][u0-9]+/: 'r' for reading, 'w' for writing, 'a' for appending, 'g' for gzip rather than BGZF compression (with 'w' only), and digit specifies the zlib compression level. Note that there is a distinction between 'u' and '0': the first yields plain uncompressed output whereas the latter outputs uncompressed data wrapped in the zlib format. |
- Returns
- BGZF file handler; 0 on error
int bgzf_flush |
( |
BGZF * |
fp | ) |
|
Write the data in the buffer to the file.
int bgzf_flush_try |
( |
BGZF * |
fp, |
|
|
ssize_t |
size |
|
) |
| |
Flush the file if the remaining buffer size is smaller than size
- Returns
- 0 if flushing succeeded or was not needed; negative on error
int bgzf_getc |
( |
BGZF * |
fp | ) |
|
Read one byte from a BGZF file. It is faster than bgzf_read()
- Parameters
-
- Returns
- byte read; -1 on end-of-file or error
Read one line from a BGZF file. It is faster than bgzf_getc()
- Parameters
-
fp | BGZF file handler |
delim | delimitor |
str | string to write to; must be initialized |
- Returns
- length of the string; 0 on end-of-file; negative on error
BGZF* bgzf_hopen |
( |
struct hFILE * |
fp, |
|
|
const char * |
mode |
|
) |
| |
Open an existing hFILE stream for reading or writing.
int bgzf_index_build_init |
( |
BGZF * |
fp | ) |
|
Tell BGZF to build index while compressing.
- Parameters
-
fp | BGZF file handler; can be opened for reading or writing. |
Returns 0 on success and -1 on error.
int bgzf_index_dump |
( |
BGZF * |
fp, |
|
|
const char * |
bname, |
|
|
const char * |
suffix |
|
) |
| |
Save BGZF index
- Parameters
-
fp | BGZF file handler |
bname | base name |
suffix | suffix to add to bname (can be NULL) |
Returns 0 on success and -1 on error.
int bgzf_index_load |
( |
BGZF * |
fp, |
|
|
const char * |
bname, |
|
|
const char * |
suffix |
|
) |
| |
Load BGZF index
- Parameters
-
fp | BGZF file handler |
bname | base name |
suffix | suffix to add to bname (can be NULL) |
Returns 0 on success and -1 on error.
int bgzf_is_bgzf |
( |
const char * |
fn | ) |
|
Check if a file is in the BGZF format
- Parameters
-
- Returns
- 1 if fn is BGZF; 0 if not or on I/O error
int bgzf_mt |
( |
BGZF * |
fp, |
|
|
int |
n_threads, |
|
|
int |
n_sub_blks |
|
) |
| |
Enable multi-threading (only effective on writing and when the library was compiled with -DBGZF_MT)
- Parameters
-
fp | BGZF file handler; must be opened for writing |
n_threads | #threads used for writing |
n_sub_blks | #blocks processed by each thread; a value 64-256 is recommended |
BGZF* bgzf_open |
( |
const char * |
path, |
|
|
const char * |
mode |
|
) |
| |
Open the specified file for reading or writing.
ssize_t bgzf_raw_read |
( |
BGZF * |
fp, |
|
|
void * |
data, |
|
|
size_t |
length |
|
) |
| |
Read up to length bytes directly from the underlying stream without decompressing. Bypasses BGZF blocking, so must be used with care in specialised circumstances only.
- Parameters
-
fp | BGZF file handler |
data | data array to read into |
length | number of raw bytes to read |
- Returns
- number of bytes actually read; 0 on end-of-file and -1 on error
ssize_t bgzf_raw_write |
( |
BGZF * |
fp, |
|
|
const void * |
data, |
|
|
size_t |
length |
|
) |
| |
Write length bytes directly to the underlying stream without compressing. Bypasses BGZF blocking, so must be used with care in specialised circumstances only.
- Parameters
-
fp | BGZF file handler |
data | data array to write |
length | number of raw bytes to write |
- Returns
- number of bytes actually written; -1 on error
ssize_t bgzf_read |
( |
BGZF * |
fp, |
|
|
void * |
data, |
|
|
size_t |
length |
|
) |
| |
Read up to length bytes from the file storing into data.
- Parameters
-
fp | BGZF file handler |
data | data array to read into |
length | size of data to read |
- Returns
- number of bytes actually read; 0 on end-of-file and -1 on error
int bgzf_read_block |
( |
BGZF * |
fp | ) |
|
Read the next BGZF block.
int64_t bgzf_seek |
( |
BGZF * |
fp, |
|
|
int64_t |
pos, |
|
|
int |
whence |
|
) |
| |
Set the file to read from the location specified by pos.
- Parameters
-
fp | BGZF file handler |
pos | virtual file offset returned by bgzf_tell() |
whence | must be SEEK_SET |
- Returns
- 0 on success and -1 on error
void bgzf_set_cache_size |
( |
BGZF * |
fp, |
|
|
int |
size |
|
) |
| |
Set the cache size. Only effective when compiled with -DBGZF_CACHE.
- Parameters
-
fp | BGZF file handler |
size | size of cache in bytes; 0 to disable caching (default) |
int bgzf_useek |
( |
BGZF * |
fp, |
|
|
long |
uoffset, |
|
|
int |
where |
|
) |
| |
Position BGZF at the uncompressed offset
- Parameters
-
fp | BGZF file handler; must be opened for reading |
uoffset | file offset in the uncompressed data |
where | SEEK_SET supported atm |
Returns 0 on success and -1 on error.
long bgzf_utell |
( |
BGZF * |
fp | ) |
|
Position in uncompressed BGZF
- Parameters
-
fp | BGZF file handler; must be opened for reading |
Returns the current offset on success and -1 on error.
ssize_t bgzf_write |
( |
BGZF * |
fp, |
|
|
const void * |
data, |
|
|
size_t |
length |
|
) |
| |
Write length bytes from data to the file. If no I/O errors occur, the complete length bytes will be written (or queued for writing).
- Parameters
-
fp | BGZF file handler |
data | data array to write |
length | size of data to write |
- Returns
- number of bytes written (i.e., length); negative on error