1 module nxt.bzlib; 2 3 pragma(lib, "bz2"); // Ubuntu: sudo apt-get install libbz2-dev 4 5 extern(C) nothrow @nogc: 6 7 enum BZ_RUN = 0; 8 enum BZ_FLUSH = 1; 9 enum BZ_FINISH = 2; 10 11 enum BZ_OK = 0; 12 enum BZ_RUN_OK = 1; 13 enum BZ_FLUSH_OK = 2; 14 enum BZ_FINISH_OK = 3; 15 enum BZ_STREAM_END = 4; 16 enum BZ_SEQUENCE_ERROR = -1; 17 enum BZ_PARAM_ERROR = -2; 18 enum BZ_MEM_ERROR = -3; 19 enum BZ_DATA_ERROR = -4; 20 enum BZ_DATA_ERROR_MAGIC = -5; 21 enum BZ_IO_ERROR = -6; 22 enum BZ_UNEXPECTED_EOF = -7; 23 enum BZ_OUTBUFF_FULL = -8; 24 enum BZ_CONFIG_ERROR = -9; 25 26 struct bz_stream 27 { 28 ubyte* next_in; 29 uint avail_in; 30 uint total_in_lo32; 31 uint total_in_hi32; 32 33 ubyte* next_out; 34 uint avail_out; 35 uint total_out_lo32; 36 uint total_out_hi32; 37 38 void* state; 39 40 void* function(void*, int, int) nothrow bzalloc; 41 void function(void*, void*) nothrow bzfree; 42 void* opaque; 43 } 44 45 /*-- Core (low-level) library functions --*/ 46 47 int BZ2_bzCompressInit(bz_stream* strm, 48 int blockSize100k, 49 int verbosity, 50 int workFactor); 51 52 int BZ2_bzCompress(bz_stream* strm, 53 int action); 54 55 int BZ2_bzCompressEnd(bz_stream* strm); 56 57 int BZ2_bzDecompressInit(bz_stream* strm, 58 int verbosity, 59 int small); 60 61 int BZ2_bzDecompress(bz_stream* strm); 62 63 int BZ2_bzDecompressEnd(bz_stream *strm); 64 65 /*-- High(er) level library functions --*/ 66 67 version(BZ_NO_STDIO) {} 68 else 69 { 70 import core.stdc.stdio; 71 72 enum BZ_MAX_UNUSED = 5000; 73 74 struct BZFILE; 75 76 BZFILE* BZ2_bzReadOpen(int* bzerror, 77 FILE* f, 78 int verbosity, 79 int small, 80 void* unused, 81 int nUnused); 82 83 void BZ2_bzReadClose(int* bzerror, 84 BZFILE* b); 85 86 void BZ2_bzReadGetUnused(int* bzerror, 87 BZFILE* b, 88 void** unused, 89 int* nUnused); 90 91 int BZ2_bzRead(int* bzerror, 92 BZFILE* b, 93 void* buf, 94 int len); 95 96 BZFILE* BZ2_bzWriteOpen(int* bzerror, 97 FILE* f, 98 int blockSize100k, 99 int verbosity, 100 int workFactor 101 ); 102 103 void BZ2_bzWrite(int* bzerror, 104 BZFILE* b, 105 void* buf, 106 int len); 107 108 void BZ2_bzWriteClose(int* bzerror, 109 BZFILE* b, 110 int abandon, 111 uint* nbytes_in, 112 uint* nbytes_out); 113 114 void BZ2_bzWriteClose64(int* bzerror, 115 BZFILE* b, 116 int abandon, 117 uint* nbytes_in_lo32, 118 uint* nbytes_in_hi32, 119 uint* nbytes_out_lo32, 120 uint* nbytes_out_hi32); 121 } 122 123 /*-- Utility functions --*/ 124 125 int BZ2_bzBuffToBuffCompress(ubyte* dest, 126 uint* destLen, 127 ubyte* source, 128 uint sourceLen, 129 int blockSize100k, 130 int verbosity, 131 int workFactor); 132 133 int BZ2_bzBuffToBuffDecompress(ubyte* dest, 134 uint* destLen, 135 ubyte* source, 136 uint sourceLen, 137 int small, 138 int verbosity); 139 140 141 /*-- 142 Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp) 143 to support better zlib compatibility. 144 This code is not _officially_ part of libbzip2 (yet); 145 I haven't tested it, documented it, or considered the 146 threading-safeness of it. 147 If this code breaks, please contact both Yoshioka and me. 148 --*/ 149 150 const(char)* BZ2_bzlibVersion(); 151 152 BZFILE* BZ2_bzopen(in const(char)* path, 153 in const(char)* mode); 154 155 BZFILE * BZ2_bzdopen(int fd, 156 in const(char)* mode); 157 158 int BZ2_bzread(scope BZFILE* b, 159 scope void* buf, 160 int len); 161 162 int BZ2_bzwrite(scope BZFILE* b, 163 scope void* buf, 164 int len); 165 166 int BZ2_bzflush(scope BZFILE* b); 167 168 void BZ2_bzclose(scope BZFILE* b); 169 170 const(char)* BZ2_bzerror(scope BZFILE *b, 171 int *errnum);