1 /******************************************************************************* 2 3 D bindings to zlib compression library. 4 5 Needs -lz when linking. 6 7 Copyright: 8 Copyright (c) 2004-2009 Tango contributors. 9 Some parts copyright (c) 2009-2016 dunnhumby Germany GmbH. 10 All rights reserved. 11 12 License: 13 Tango Dual License: 3-Clause BSD License / Academic Free License v3.0. 14 See LICENSE_TANGO.txt for details. 15 16 Bear in mind this module provides bindings to an external library that 17 has its own license, which might be more restrictive. Please check the 18 external library license to see which conditions apply for linking. 19 20 *******************************************************************************/ 21 22 module ocean.util.compress.c.zlib; 23 24 import ocean.meta.types.Qualifiers; 25 import ocean.meta.types.Typedef; 26 27 /// See original's library documentation for details. 28 static immutable ZLIB_VERSION = "1.2.3".ptr; 29 /// See original's library documentation for details. 30 static immutable uint ZLIB_VERNUM = 0x1230; 31 /// See original's library documentation for details. 32 static immutable void* Z_NULL = null; 33 34 extern (C): 35 private 36 { 37 import core.stdc.config : c_long, c_ulong; 38 39 import core.sys.posix.sys.types : z_off_t = off_t; 40 41 alias ubyte Byte; 42 alias uint uInt; 43 alias c_ulong uLong; 44 45 alias Byte Bytef; 46 alias char charf; 47 alias int intf; 48 alias uInt uIntf; 49 alias uLong uLongf; 50 51 alias void* voidpc; // TODO: normally const 52 alias void* voidpf; 53 alias void* voidp; 54 55 alias voidpf function(voidpf opaque, uInt items, uInt size) alloc_func; 56 alias void function(voidpf opaque, voidpf address) free_func; 57 58 struct internal_state {} 59 } 60 61 struct z_stream 62 { 63 Bytef* next_in; 64 uInt avail_in; 65 uLong total_in; 66 67 Bytef* next_out; 68 uInt avail_out; 69 uLong total_out; 70 71 char* msg; 72 internal_state* state; 73 74 alloc_func zalloc; 75 free_func zfree; 76 voidpf opaque; 77 78 int data_type; 79 uLong adler; 80 uLong reserved; 81 } 82 83 /// See original's library documentation for details. 84 alias z_stream* z_streamp; 85 86 /// See original's library documentation for details. 87 struct gz_header 88 { 89 int text; 90 uLong time; 91 int xflags; 92 int os; 93 Bytef* extra; 94 uInt extra_len; 95 uInt extra_max; 96 Bytef* name; 97 uInt name_max; 98 Bytef* comment; 99 uInt comm_max; 100 int hcrc; 101 int done; 102 } 103 104 /// See original's library documentation for details. 105 alias gz_header* gz_headerp; 106 107 108 109 /// See original's library documentation for details. 110 enum 111 { 112 Z_NO_FLUSH = 0, 113 Z_PARTIAL_FLUSH = 1, 114 Z_SYNC_FLUSH = 2, 115 Z_FULL_FLUSH = 3, 116 Z_FINISH = 4, 117 Z_BLOCK = 5, 118 } 119 120 /// See original's library documentation for details. 121 enum 122 { 123 Z_OK = 0, 124 Z_STREAM_END = 1, 125 Z_NEED_DICT = 2, 126 Z_ERRNO = -1, 127 Z_STREAM_ERROR = -2, 128 Z_DATA_ERROR = -3, 129 Z_MEM_ERROR = -4, 130 Z_BUF_ERROR = -5, 131 Z_VERSION_ERROR = -6, 132 } 133 134 /// See original's library documentation for details. 135 enum 136 { 137 Z_NO_COMPRESSION = 0, 138 Z_BEST_SPEED = 1, 139 Z_BEST_COMPRESSION = 9, 140 Z_DEFAULT_COMPRESSION = -1, 141 } 142 143 /// See original's library documentation for details. 144 enum 145 { 146 Z_FILTERED = 1, 147 Z_HUFFMAN_ONLY = 2, 148 Z_RLE = 3, 149 Z_FIXED = 4, 150 Z_DEFAULT_STRATEGY = 0, 151 } 152 153 /// See original's library documentation for details. 154 enum 155 { 156 Z_BINARY = 0, 157 Z_TEXT = 1, 158 Z_ASCII = Z_TEXT, 159 Z_UNKNOWN = 2, 160 } 161 162 /// See original's library documentation for details. 163 enum 164 { 165 Z_DEFLATED = 8, 166 } 167 168 /// See original's library documentation for details. 169 alias zlibVersion zlib_version; 170 171 172 /// See original's library documentation for details. 173 char* zlibVersion(); 174 175 176 177 /// See original's library documentation for details. 178 int deflate(z_streamp strm, int flush); 179 180 181 /// See original's library documentation for details. 182 int deflateEnd(z_streamp strm); 183 184 185 186 187 /// See original's library documentation for details. 188 int inflate(z_streamp strm, int flush); 189 190 191 /// See original's library documentation for details. 192 int inflateEnd(z_streamp strm); 193 194 195 196 197 /// See original's library documentation for details. 198 int deflateSetDictionary(z_streamp strm, 199 Bytef* dictionary, 200 uInt dictLength); 201 202 /// See original's library documentation for details. 203 int deflateCopy(z_streamp dest, 204 z_streamp source); 205 206 /// See original's library documentation for details. 207 int deflateReset(z_streamp strm); 208 209 /// See original's library documentation for details. 210 int deflateParams(z_streamp strm, 211 int level, 212 int strategy); 213 214 /// See original's library documentation for details. 215 int deflateTune(z_streamp strm, 216 int good_length, 217 int max_lazy, 218 int nice_length, 219 int max_chain); 220 221 /// See original's library documentation for details. 222 uLong deflateBound(z_streamp strm, 223 uLong sourceLen); 224 225 /// See original's library documentation for details. 226 int deflatePrime(z_streamp strm, 227 int bits, 228 int value); 229 230 /// See original's library documentation for details. 231 int deflateSetHeader(z_streamp strm, 232 gz_headerp head); 233 234 235 /// See original's library documentation for details. 236 int inflateSetDictionary(z_streamp strm, 237 Bytef* dictionary, 238 uInt dictLength); 239 240 /// See original's library documentation for details. 241 int inflateSync(z_streamp strm); 242 243 /// See original's library documentation for details. 244 int inflateCopy(z_streamp dest, 245 z_streamp source); 246 247 /// See original's library documentation for details. 248 int inflateReset(z_streamp strm); 249 250 /// See original's library documentation for details. 251 int inflatePrime(z_streamp strm, 252 int bits, 253 int value); 254 255 /// See original's library documentation for details. 256 int inflateGetHeader(z_streamp strm, 257 gz_headerp head); 258 259 260 alias uint function(void*, ubyte**) in_func; 261 alias int function(void*, ubyte*, uint) out_func; 262 263 /// See original's library documentation for details. 264 int inflateBack(z_streamp strm, 265 scope in_func in_fn, 266 void* in_desc, 267 scope out_func out_fn, 268 void* out_desc); 269 270 /// See original's library documentation for details. 271 int inflateBackEnd(z_streamp strm); 272 273 /// See original's library documentation for details. 274 uLong zlibCompileFlags(); 275 276 277 278 279 /// See original's library documentation for details. 280 int compress(Bytef* dest, 281 uLongf* destLen, 282 Bytef* source, 283 uLong sourceLen); 284 285 /// See original's library documentation for details. 286 int compress2(Bytef* dest, 287 uLongf* destLen, 288 Bytef* source, 289 uLong sourceLen, 290 int level); 291 292 /// See original's library documentation for details. 293 uLong compressBound(uLong sourceLen); 294 295 /// See original's library documentation for details. 296 int uncompress(Bytef* dest, 297 uLongf* destLen, 298 Bytef* source, 299 uLong sourceLen); 300 301 302 /// See original's library documentation for details. 303 mixin(Typedef!(voidp, "gzFile")); 304 305 /// See original's library documentation for details. 306 gzFile gzopen(char* path, char* mode); 307 308 /// See original's library documentation for details. 309 gzFile gzdopen(int fd, char* mode); 310 311 /// See original's library documentation for details. 312 int gzsetparams(gzFile file, int level, int strategy); 313 314 /// See original's library documentation for details. 315 int gzread(gzFile file, voidp buf, uint len); 316 317 /// See original's library documentation for details. 318 int gzwrite(gzFile file, voidpc buf, uint len); 319 320 /// See original's library documentation for details. 321 int gzprintf (gzFile file, char* format, ...); 322 323 /// See original's library documentation for details. 324 int gzputs(gzFile file, char* s); 325 326 /// See original's library documentation for details. 327 char* gzgets(gzFile file, char* buf, int len); 328 329 /// See original's library documentation for details. 330 int gzputc(gzFile file, int c); 331 332 /// See original's library documentation for details. 333 int gzgetc (gzFile file); 334 335 /// See original's library documentation for details. 336 int gzungetc(int c, gzFile file); 337 338 /// See original's library documentation for details. 339 int gzflush(gzFile file, int flush); 340 341 /// See original's library documentation for details. 342 z_off_t gzseek (gzFile file, z_off_t offset, int whence); 343 344 /// See original's library documentation for details. 345 int gzrewind(gzFile file); 346 347 /// See original's library documentation for details. 348 z_off_t gztell (gzFile file); 349 350 /// See original's library documentation for details. 351 int gzeof(gzFile file); 352 353 /// See original's library documentation for details. 354 int gzdirect(gzFile file); 355 356 /// See original's library documentation for details. 357 int gzclose(gzFile file); 358 359 /// See original's library documentation for details. 360 char* gzerror(gzFile file, int* errnum); 361 362 /// See original's library documentation for details. 363 void gzclearerr(gzFile file); 364 365 /* checksum functions */ 366 367 368 /// See original's library documentation for details. 369 uLong adler32(uLong adler, Bytef* buf, uInt len); 370 371 /// See original's library documentation for details. 372 uLong adler32_combine(uLong adler1, uLong adler2, z_off_t len2); 373 374 /// See original's library documentation for details. 375 uLong crc32(uLong crc, Bytef* buf, uInt len); 376 377 /// See original's library documentation for details. 378 uLong crc32_combine(uLong crc1, uLong crc2, z_off_t len2); 379 380 381 382 /* various hacks, don't look :) */ 383 384 /// See original's library documentation for details. 385 int deflateInit_(z_streamp strm, 386 int level, 387 const(char)* ver, 388 int stream_size); 389 /// See original's library documentation for details. 390 int inflateInit_(z_streamp strm, 391 const(char)* ver, 392 int stream_size); 393 /// See original's library documentation for details. 394 int deflateInit2_(z_streamp strm, 395 int level, 396 int method, 397 int windowBits, 398 int memLevel, 399 int strategy, 400 const(char)* ver, 401 int stream_size); 402 /// See original's library documentation for details. 403 int inflateInit2_(z_streamp strm, 404 int windowBits, 405 const(char)* ver, 406 int stream_size); 407 /// See original's library documentation for details. 408 int inflateBackInit_(z_streamp strm, 409 int windowBits, 410 ubyte* window, 411 const(char)* ver, 412 int stream_size); 413 414 extern (D) int deflateInit(z_streamp strm, 415 int level) 416 { 417 return deflateInit_(strm, 418 level, 419 ZLIB_VERSION, 420 z_stream.sizeof); 421 } 422 423 extern (D) int inflateInit(z_streamp strm) 424 { 425 return inflateInit_(strm, 426 ZLIB_VERSION, 427 z_stream.sizeof); 428 } 429 430 extern (D) int deflateInit2(z_streamp strm, 431 int level, 432 int method, 433 int windowBits, 434 int memLevel, 435 int strategy) 436 { 437 return deflateInit2_(strm, 438 level, 439 method, 440 windowBits, 441 memLevel, 442 strategy, 443 ZLIB_VERSION, 444 z_stream.sizeof); 445 } 446 447 extern (D) int inflateInit2(z_streamp strm, 448 int windowBits) 449 { 450 return inflateInit2_(strm, 451 windowBits, 452 ZLIB_VERSION, 453 z_stream.sizeof); 454 } 455 456 extern (D) int inflateBackInit(z_streamp strm, 457 int windowBits, 458 ubyte* window) 459 { 460 return inflateBackInit_(strm, 461 windowBits, 462 window, 463 ZLIB_VERSION, 464 z_stream.sizeof); 465 } 466 467 /// See original's library documentation for details. 468 char* zError(int); 469 /// See original's library documentation for details. 470 int inflateSyncPoint(z_streamp z); 471 /// See original's library documentation for details. 472 uLongf* get_crc_table();