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