3 * SOFTWARE COPYRIGHT NOTICE AGREEMENT
4 * This software and its documentation are copyright 2008 by the
5 * Broad Institute/Massachusetts Institute of Technology. All rights are reserved.
7 * This software is supplied without any warranty or guaranteed support whatsoever.
8 * Neither the Broad Institute nor MIT can be responsible for its use, misuse,
22 typedef unsigned char uint8_t;
23 typedef short int16_t;
24 typedef unsigned short uint16_t;
26 typedef unsigned int uint32_t;
27 typedef long long int64_t;
28 typedef unsigned long long uint64_t;
30 #define ftello(a) _ftelli64(a)
31 #define fseeko(a,b,c) _fseeki64(a,b,c)
32 #define strcasecmp _stricmp
34 #define fdopen _fdopen
42 char open_mode; // 'r' or 'w'
45 int uncompressed_block_size;
46 int compressed_block_size;
47 void* uncompressed_block;
48 void* compressed_block;
49 int64_t block_address;
60 * Open an existing file descriptor for reading or writing.
61 * Mode must be either "r" or "w".
62 * A subsequent bgzf_close will not close the file descriptor.
63 * Returns null on error.
65 BGZF* bgzf_fdopen(int fd, const char* __restrict mode);
68 * Open the specified file for reading or writing.
69 * Mode must be either "r" or "w".
70 * Returns null on error.
72 BGZF* bgzf_open(const char* path, const char* __restrict mode);
75 * Close the BGZ file and free all associated resources.
76 * Does not close the underlying file descriptor if created with bgzf_fdopen.
77 * Returns zero on success, -1 on error.
79 int bgzf_close(BGZF* fp);
82 * Read up to length bytes from the file storing into data.
83 * Returns the number of bytes actually read.
84 * Returns zero on end of file.
85 * Returns -1 on error.
87 int bgzf_read(BGZF* fp, void* data, int length);
90 * Write length bytes from data to the file.
91 * Returns the number of bytes written.
92 * Returns -1 on error.
94 int bgzf_write(BGZF* fp, const void* data, int length);
97 * Return a virtual file pointer to the current location in the file.
98 * No interpetation of the value should be made, other than a subsequent
99 * call to bgzf_seek can be used to position the file at the same point.
100 * Return value is non-negative on success.
101 * Returns -1 on error.
103 int64_t bgzf_tell(BGZF* fp);
106 * Set the file to read from the location specified by pos, which must
107 * be a value previously returned by bgzf_tell for this file (but not
108 * necessarily one returned by this file handle).
109 * The where argument must be SEEK_SET.
110 * Seeking on a file opened for write is not supported.
111 * Returns zero on success, -1 on error.
113 int64_t bgzf_seek(BGZF* fp, int64_t pos, int where);