1 /*-------------------------------------------------------------*/ 2 /*--- Public header file for the library. ---*/ 3 /*--- bzlib.h ---*/ 4 /*-------------------------------------------------------------*/ 5 /** 6 * This file is part of bzip2/libbzip2, a program and library for 7 * lossless, block-sorting data compression. 8 * 9 * bzip2/libbzip2 version 1.0.6 of 6 September 2010 10 * Copyright (C) 1996-2010 Julian Seward <jseward@bzip.org> 11 * 12 * Please read the WARNING, DISCLAIMER and PATENTS sections in the 13 * README file. 14 * 15 * This program is released under the terms of the license contained 16 * in the file LICENSE. 17 */ 18 module bzlib; 19 20 extern(C) nothrow: 21 22 enum BZ_RUN = 0; 23 enum BZ_FLUSH = 1; 24 enum BZ_FINISH = 2; 25 26 enum BZ_OK = 0; 27 enum BZ_RUN_OK = 1; 28 enum BZ_FLUSH_OK = 2; 29 enum BZ_FINISH_OK = 3; 30 enum BZ_STREAM_END = 4; 31 enum BZ_SEQUENCE_ERROR = -1; 32 enum BZ_PARAM_ERROR = -2; 33 enum BZ_MEM_ERROR = -3; 34 enum BZ_DATA_ERROR = -4; 35 enum BZ_DATA_ERROR_MAGIC = -5; 36 enum BZ_IO_ERROR = -6; 37 enum BZ_UNEXPECTED_EOF = -7; 38 enum BZ_OUTBUFF_FULL = -8; 39 enum BZ_CONFIG_ERROR = -9; 40 41 42 struct bz_stream 43 { 44 ubyte* next_in; 45 uint avail_in; 46 uint total_in_lo32; 47 uint total_in_hi32; 48 49 ubyte* next_out; 50 uint avail_out; 51 uint total_out_lo32; 52 uint total_out_hi32; 53 54 void* state; 55 56 void* function(void*, int, int) nothrow bzalloc; 57 void function(void*, void*) nothrow bzfree; 58 void* opaque; 59 } 60 61 /*-- Core (low-level) library functions --*/ 62 63 int BZ2_bzCompressInit( 64 bz_stream* strm, 65 int blockSize100k, 66 int verbosity, 67 int workFactor 68 ); 69 70 int BZ2_bzCompress( 71 bz_stream* strm, 72 int action 73 ); 74 75 int BZ2_bzCompressEnd( 76 bz_stream* strm 77 ); 78 79 int BZ2_bzDecompressInit( 80 bz_stream* strm, 81 int verbosity, 82 int small 83 ); 84 85 int BZ2_bzDecompress( 86 bz_stream* strm 87 ); 88 89 int BZ2_bzDecompressEnd( 90 bz_stream *strm 91 ); 92 93 /*-- High(er) level library functions --*/ 94 95 version(BZ_NO_STDIO) {} 96 else 97 { 98 import core.stdc.stdio; 99 100 enum BZ_MAX_UNUSED = 5000; 101 102 alias void BZFILE; 103 104 BZFILE* BZ2_bzReadOpen( 105 int* bzerror, 106 FILE* f, 107 int verbosity, 108 int small, 109 void* unused, 110 int nUnused 111 ); 112 113 void BZ2_bzReadClose( 114 int* bzerror, 115 BZFILE* b 116 ); 117 118 void BZ2_bzReadGetUnused( 119 int* bzerror, 120 BZFILE* b, 121 void** unused, 122 int* nUnused 123 ); 124 125 int BZ2_bzRead( 126 int* bzerror, 127 BZFILE* b, 128 void* buf, 129 int len 130 ); 131 132 BZFILE* BZ2_bzWriteOpen( 133 int* bzerror, 134 FILE* f, 135 int blockSize100k, 136 int verbosity, 137 int workFactor 138 ); 139 140 void BZ2_bzWrite( 141 int* bzerror, 142 BZFILE* b, 143 void* buf, 144 int len 145 ); 146 147 void BZ2_bzWriteClose( 148 int* bzerror, 149 BZFILE* b, 150 int abandon, 151 uint* nbytes_in, 152 uint* nbytes_out 153 ); 154 155 void BZ2_bzWriteClose64( 156 int* bzerror, 157 BZFILE* b, 158 int abandon, 159 uint* nbytes_in_lo32, 160 uint* nbytes_in_hi32, 161 uint* nbytes_out_lo32, 162 uint* nbytes_out_hi32 163 ); 164 } 165 166 /*-- Utility functions --*/ 167 168 int BZ2_bzBuffToBuffCompress( 169 ubyte* dest, 170 uint* destLen, 171 ubyte* source, 172 uint sourceLen, 173 int blockSize100k, 174 int verbosity, 175 int workFactor 176 ); 177 178 int BZ2_bzBuffToBuffDecompress( 179 ubyte* dest, 180 uint* destLen, 181 ubyte* source, 182 uint sourceLen, 183 int small, 184 int verbosity 185 ); 186 187 188 /*-- 189 Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp) 190 to support better zlib compatibility. 191 This code is not _officially_ part of libbzip2 (yet); 192 I haven't tested it, documented it, or considered the 193 threading-safeness of it. 194 If this code breaks, please contact both Yoshioka and me. 195 --*/ 196 197 const(char)* BZ2_bzlibVersion(); 198 199 version(BZ_NO_STDIO) {} 200 else 201 { 202 BZFILE* BZ2_bzopen( 203 const(char)* path, 204 const(char)* mode 205 ); 206 207 BZFILE * BZ2_bzdopen( 208 int fd, 209 const(char)* mode 210 ); 211 212 int BZ2_bzread( 213 BZFILE* b, 214 void* buf, 215 int len 216 ); 217 218 int BZ2_bzwrite( 219 BZFILE* b, 220 void* buf, 221 int len 222 ); 223 224 int BZ2_bzflush( 225 BZFILE* b 226 ); 227 228 void BZ2_bzclose( 229 BZFILE* b 230 ); 231 232 const(char)* BZ2_bzerror( 233 BZFILE *b, 234 int *errnum 235 ); 236 } 237 /*-------------------------------------------------------------*/ 238 /*--- end bzlib.h ---*/ 239 /*-------------------------------------------------------------*/