modified: makefile
[GalaxyCodeBases.git] / BGI / SOAPdenovo2 / standardPregraph / inc / bgzf.h
blob7b93d764ad65acbc7a4595748c59eb70c8360863
1 /* The MIT License
3 Copyright (c) 2008 Broad Institute / Massachusetts Institute of Technology
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 THE SOFTWARE.
24 #ifndef __BGZF_H
25 #define __BGZF_H
27 #include <stdint.h>
28 #include <stdio.h>
29 #include <stdbool.h>
30 #include <zlib.h>
31 #ifdef _USE_KNETFILE
32 #include "knetfile.h"
33 #endif
35 //typedef int8_t bool;
37 typedef struct
39 int file_descriptor;
40 char open_mode; // 'r' or 'w'
41 bool owned_file, is_uncompressed;
42 #ifdef _USE_KNETFILE
43 union
45 knetFile * fpr;
46 FILE * fpw;
47 } x;
48 #else
49 FILE * file;
50 #endif
51 int uncompressed_block_size;
52 int compressed_block_size;
53 void * uncompressed_block;
54 void * compressed_block;
55 int64_t block_address;
56 int block_length;
57 int block_offset;
58 int cache_size;
59 const char * error;
60 void * cache; // a pointer to a hash table
61 } BGZF;
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
68 * Open an existing file descriptor for reading or writing.
69 * Mode must be either "r" or "w".
70 * A subsequent bgzf_close will not close the file descriptor.
71 * Returns null on error.
73 BGZF * bgzf_fdopen ( int fd, const char * __restrict mode );
76 * Open the specified file for reading or writing.
77 * Mode must be either "r" or "w".
78 * Returns null on error.
80 BGZF * bgzf_open ( const char * path, const char * __restrict mode );
83 * Close the BGZ file and free all associated resources.
84 * Does not close the underlying file descriptor if created with bgzf_fdopen.
85 * Returns zero on success, -1 on error.
87 int bgzf_close ( BGZF * fp );
90 * Read up to length bytes from the file storing into data.
91 * Returns the number of bytes actually read.
92 * Returns zero on end of file.
93 * Returns -1 on error.
95 int bgzf_read ( BGZF * fp, void * data, int length );
98 * Write length bytes from data to the file.
99 * Returns the number of bytes written.
100 * Returns -1 on error.
102 int bgzf_write ( BGZF * fp, const void * data, int length );
105 * Return a virtual file pointer to the current location in the file.
106 * No interpetation of the value should be made, other than a subsequent
107 * call to bgzf_seek can be used to position the file at the same point.
108 * Return value is non-negative on success.
109 * Returns -1 on error.
111 int64_t bgzf_tell ( BGZF * fp );
114 * Set the file to read from the location specified by pos, which must
115 * be a value previously returned by bgzf_tell for this file (but not
116 * necessarily one returned by this file handle).
117 * The where argument must be SEEK_SET.
118 * Seeking on a file opened for write is not supported.
119 * Returns zero on success, -1 on error.
121 int64_t bgzf_seek ( BGZF * fp, int64_t pos, int where );
124 * Set the cache size. Zero to disable. By default, caching is
125 * disabled. The recommended cache size for frequent random access is
126 * about 8M bytes.
128 void bgzf_set_cache_size ( BGZF * fp, int cache_size );
130 int bgzf_check_EOF ( BGZF * fp );
132 #ifdef __cplusplus
134 #endif
136 #endif