1 
2 /***************************************************************************
3  *                    __            __ _ ___________                       *
4  *                    \ \          / /| |____   ____|                      *
5  *                     \ \        / / | |    | |                           *
6  *                      \ \  /\  / /  | |    | |                           *
7  *                       \ \/  \/ /   | |    | |                           *
8  *                        \  /\  /    | |    | |                           *
9  *                         \/  \/     |_|    |_|                           *
10  *                                                                         *
11  *                           Wiimms ISO Tools                              *
12  *                         http://wit.wiimm.de/                            *
13  *                                                                         *
14  ***************************************************************************
15  *                                                                         *
16  *   This file is part of the WIT project.                                 *
17  *   Visit http://wit.wiimm.de/ for project details and sources.           *
18  *                                                                         *
19  *   Copyright (c) 2009-2013 by Dirk Clemens <wiimm@wiimm.de>              *
20  *                                                                         *
21  ***************************************************************************
22  *                                                                         *
23  *   This program is free software; you can redistribute it and/or modify  *
24  *   it under the terms of the GNU General Public License as published by  *
25  *   the Free Software Foundation; either version 2 of the License, or     *
26  *   (at your option) any later version.                                   *
27  *                                                                         *
28  *   This program is distributed in the hope that it will be useful,       *
29  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
30  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
31  *   GNU General Public License for more details.                          *
32  *                                                                         *
33  *   See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt       *
34  *                                                                         *
35  ***************************************************************************/
36 
37 #ifndef WIT_LIB_BZIP2_H
38 #define WIT_LIB_BZIP2_H 1
39 #ifndef NO_BZIP2
40 
41 #define _GNU_SOURCE 1
42 
43 #include "lib-std.h"
44 
45 //
46 ///////////////////////////////////////////////////////////////////////////////
47 ///////////////			  definitions			///////////////
48 ///////////////////////////////////////////////////////////////////////////////
49 
50 #ifndef _BZLIB_H
51     typedef void BZFILE;
52 #endif
53 
54 //-----------------------------------------------------------------------------
55 
56 typedef struct BZIP2_t
57 {
58     File_t		* file;		// IO file
59     BZFILE		* handle;	// bzip2 handle
60     int			compr_level;	// active compression level
61 
62 } BZIP2_t;
63 
64 //
65 ///////////////////////////////////////////////////////////////////////////////
66 ///////////////			  helpers			///////////////
67 ///////////////////////////////////////////////////////////////////////////////
68 
69 ccp GetMessageBZIP2
70 (
71     int			err,		// error code
72     ccp			unkown_error	// result for unkown error codes
73 );
74 
75 //-----------------------------------------------------------------------------
76 
77 int CalcCompressionLevelBZIP2
78 (
79     int			compr_level	// valid are 1..9 / 0: use default value
80 );
81 
82 //-----------------------------------------------------------------------------
83 
84 u32 CalcMemoryUsageBZIP2
85 (
86     int			compr_level,	// valid are 1..9 / 0: use default value
87     bool		is_writing	// false: reading mode, true: writing mode
88 );
89 
90 //
91 ///////////////////////////////////////////////////////////////////////////////
92 ///////////////			BZIP2 writing			///////////////
93 ///////////////////////////////////////////////////////////////////////////////
94 
95 enumError EncBZIP2_Open
96 (
97     BZIP2_t		* bz,		// data structure, will be initialized
98     File_t		* file,		// destination file
99     int			compr_level	// valid are 1..9 / 0: use default value
100 );
101 
102 //-----------------------------------------------------------------------------
103 
104 enumError EncBZIP2_Write
105 (
106     BZIP2_t		* bz,		// created by EncBZIP2_Open()
107     const void		* data,		// data to write
108     size_t		data_size	// size of data to write
109 );
110 
111 //-----------------------------------------------------------------------------
112 
113 enumError EncBZIP2_Close
114 (
115     BZIP2_t		* bz,		// NULL or created by EncBZIP2_Open()
116     u32			* bytes_written	// not NULL: store written bytes
117 );
118 
119 //
120 ///////////////////////////////////////////////////////////////////////////////
121 ///////////////			BZIP2 reading			///////////////
122 ///////////////////////////////////////////////////////////////////////////////
123 
124 enumError DecBZIP2_Open
125 (
126     BZIP2_t		* bz,		// data structure, will be initialized
127     File_t		* file		// source file
128 );
129 
130 //-----------------------------------------------------------------------------
131 
132 enumError DecBZIP2_Read
133 (
134     BZIP2_t		* bz,		// created by DecBZIP2_Open()
135     void		* buf,		// destination buffer
136     size_t		buf_size,	// size of destination buffer
137     u32			* buf_written	// not NULL: store bytes written to buf
138 );
139 
140 //-----------------------------------------------------------------------------
141 
142 enumError DecBZIP2_Close
143 (
144     BZIP2_t		* bz		// NULL or created by DecBZIP2_Open()
145 );
146 
147 //
148 ///////////////////////////////////////////////////////////////////////////////
149 ///////////////		    BZIP2 memory conversions		///////////////
150 ///////////////////////////////////////////////////////////////////////////////
151 
152 enumError EncBZIP2buf
153 (
154     void		*dest,		// valid destination buffer
155     uint		dest_size,	// size of 'dest'
156     uint		*dest_written,	// store num bytes written to 'dest', never NULL
157 
158     const void		*src,		// source buffer
159     uint		src_size,	// size of source buffer
160 
161     int			compr_level	// valid are 1..9 / 0: use default value
162 );
163 
164 //-----------------------------------------------------------------------------
165 
166 enumError EncBZIP2
167 (
168     u8			**dest_ptr,	// result: store destination buffer addr
169     uint		*dest_written,	// store num bytes written to 'dest', never NULL
170     bool		use_iobuf,	// true: allow thhe usage of 'iobuf'
171 
172     const void		*src,		// source buffer
173     uint		src_size,	// size of source buffer
174 
175     int			compr_level	// valid are 1..9 / 0: use default value
176 );
177 
178 //-----------------------------------------------------------------------------
179 
180 enumError DecBZIP2buf
181 (
182     void		*dest,		// valid destination buffer
183     uint		dest_size,	// size of 'dest'
184     uint		*dest_written,	// store num bytes written to 'dest', never NULL
185 
186     const void		*src,		// source buffer
187     uint		src_size	// size of source buffer
188 );
189 
190 //-----------------------------------------------------------------------------
191 
192 enumError DecBZIP2
193 (
194     u8			**dest_ptr,	// result: store destination buffer addr
195     uint		*dest_written,	// store num bytes written to 'dest', never NULL
196     const void		*src,		// source buffer
197     uint		src_size	// size of source buffer
198 );
199 
200 //
201 ///////////////////////////////////////////////////////////////////////////////
202 ///////////////				END			///////////////
203 ///////////////////////////////////////////////////////////////////////////////
204 
205 #endif // !NO_BZIP2
206 #endif // WIT_LIB_BZIP2_H 1
207 
208