1 module libbz2.bzlib;
2 private import std.c.stdio;
3
4 //----------------------------------------------------------------
5 // bzlib.d :
6 // manually translated from "bzlib.h" to d header module.
7 // 2004/08/19 k.inaba
8 //----------------------------------------------------------------
9
10 // VVV original copyright notice of "bzlib.h" VVV //
11 /*--
12 This file is a part of bzip2 and/or libbzip2, a program and
13 library for lossless, block-sorting data compression.
14
15 Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
16
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions
19 are met:
20
21 1. Redistributions of source code must retain the above copyright
22 notice, this list of conditions and the following disclaimer.
23
24 2. The origin of this software must not be misrepresented; you must
25 not claim that you wrote the original software. If you use this
26 software in a product, an acknowledgment in the product
27 documentation would be appreciated but is not required.
28
29 3. Altered source versions must be plainly marked as such, and must
30 not be misrepresented as being the original software.
31
32 4. The name of the author may not be used to endorse or promote
33 products derived from this software without specific prior written
34 permission.
35
36 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
37 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
39 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
40 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
41 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
43 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
45 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
48 Julian Seward, Cambridge, UK.
49 jseward@acm.org
50 bzip2/libbzip2 version 1.0 of 21 March 2000
51
52 This program is based on (at least) the work of:
53 Mike Burrows
54 David Wheeler
55 Peter Fenwick
56 Alistair Moffat
57 Radford Neal
58 Ian H. Witten
59 Robert Sedgewick
60 Jon L. Bentley
61
62 For more information on these sources, see the manual.
63 --*/
64
65 enum
66 {
67 BZ_RUN = 0,
68 BZ_FLUSH = 1,
69 BZ_FINISH = 2,
70 }
71
72 enum
73 {
74 BZ_OK = 0,
75 BZ_RUN_OK = 1,
76 BZ_FLUSH_OK = 2,
77 BZ_FINISH_OK = 3,
78 BZ_STREAM_END = 4,
79 BZ_SEQUENCE_ERROR = (-1),
80 BZ_PARAM_ERROR = (-2),
81 BZ_MEM_ERROR = (-3),
82 BZ_DATA_ERROR = (-4),
83 BZ_DATA_ERROR_MAGIC = (-5),
84 BZ_IO_ERROR = (-6),
85 BZ_UNEXPECTED_EOF = (-7),
86 BZ_OUTBUFF_FULL = (-8),
87 BZ_CONFIG_ERROR = (-9),
88 }
89
90 struct bz_stream
91 {
92 char *next_in;
93 uint avail_in;
94 uint total_in_lo32;
95 uint total_in_hi32;
96
97 char *next_out;
98 uint avail_out;
99 uint total_out_lo32;
100 uint total_out_hi32;
101
102 void *state;
103
104 void *(*bzalloc)(void *,int,int);
105 void (*bzfree)(void *,void *);
106 void *opaque;
107 }
108
109 extern(Windows)
110 {
111 /*-- Core (low-level) library functions --*/
112
113 int BZ2_bzCompressInit(
114 bz_stream* strm,
115 int blockSize100k,
116 int verbosity,
117 int workFactor
118 );
119
120 int BZ2_bzCompress(
121 bz_stream* strm,
122 int action
123 );
124
125 int BZ2_bzCompressEnd(
126 bz_stream* strm
127 );
128
129 int BZ2_bzDecompressInit(
130 bz_stream *strm,
131 int verbosity,
132 int small
133 );
134
135 int BZ2_bzDecompress(
136 bz_stream* strm
137 );
138
139 int BZ2_bzDecompressEnd(
140 bz_stream *strm
141 );
142
143 /*-- High(er) level library functions --*/
144
145 enum { BZ_MAX_UNUSED = 5000 }
146 alias void BZFILE;
147
148 BZFILE* BZ2_bzReadOpen(
149 int* bzerror,
150 FILE* f,
151 int verbosity,
152 int small,
153 void* unused,
154 int nUnused
155 );
156
157 void BZ2_bzReadClose(
158 int* bzerror,
159 BZFILE* b
160 );
161
162 void BZ2_bzReadGetUnused(
163 int* bzerror,
164 BZFILE* b,
165 void** unused,
166 int* nUnused
167 );
168
169 int BZ2_bzRead(
170 int* bzerror,
171 BZFILE* b,
172 void* buf,
173 int len
174 );
175
176 BZFILE* BZ2_bzWriteOpen(
177 int* bzerror,
178 FILE* f,
179 int blockSize100k,
180 int verbosity,
181 int workFactor
182 );
183
184 void BZ2_bzWrite(
185 int* bzerror,
186 BZFILE* b,
187 void* buf,
188 int len
189 );
190
191 void BZ2_bzWriteClose(
192 int* bzerror,
193 BZFILE* b,
194 int abandon,
195 uint* nbytes_in,
196 uint* nbytes_out
197 );
198
199 void BZ2_bzWriteClose64(
200 int* bzerror,
201 BZFILE* b,
202 int abandon,
203 uint* nbytes_in_lo32,
204 uint* nbytes_in_hi32,
205 uint* nbytes_out_lo32,
206 uint* nbytes_out_hi32
207 );
208
209 /*-- Utility functions --*/
210
211 int BZ2_bzBuffToBuffCompress(
212 char* dest,
213 uint* destLen,
214 char* source,
215 uint sourceLen,
216 int blockSize100k,
217 int verbosity,
218 int workFactor
219 );
220
221 int BZ2_bzBuffToBuffDecompress(
222 char* dest,
223 uint* destLen,
224 char* source,
225 int sourceLen,
226 int small,
227 int verbosity
228 );
229
230 /*--
231 Code contributed by Yoshioka Tsuneo
232 (QWF00133@niftyserve.or.jp/tsuneo-y@is.aist-nara.ac.jp),
233 to support better zlib compatibility.
234 This code is not _officially_ part of libbzip2 (yet);
235 I haven't tested it, documented it, or considered the
236 threading-safeness of it.
237 If this code breaks, please contact both Yoshioka and me.
238 --*/
239
240 char* BZ2_bzlibVersion(
241 );
242
243 BZFILE * BZ2_bzopen(
244 char *path,
245 char *mode
246 );
247
248 BZFILE * BZ2_bzdopen(
249 int fd,
250 char *mode
251 );
252
253 int BZ2_bzread(
254 BZFILE* b,
255 void* buf,
256 int len
257 );
258
259 int BZ2_bzwrite(
260 BZFILE* b,
261 void* buf,
262 int len
263 );
264
265 int BZ2_bzflush(
266 BZFILE* b
267 );
268
269 void BZ2_bzclose(
270 BZFILE* b
271 );
272
273 char * BZ2_bzerror(
274 BZFILE *b,
275 int *errnum
276 );
277 }