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