NCBI C++ ToolKit
nlmzip.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef __nlmzip__
2 #define __nlmzip__
3 
4 // Ignore warnings for ncbi included code
5 #ifdef __GNUC__ // if gcc or g++
6 # pragma GCC diagnostic push
7 # pragma GCC diagnostic ignored "-Wunused-function"
8 #endif //__GNUC__
9 
10 
11 
12 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13 
14  NOTE: NLMZIP is have very bad MT-safety !!!
15 
16  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 */
18 
19 
20 /* $Id*/
21 /*****************************************************************************
22 
23  Name: nlmzip.h distrib/internal/compr/nlmzip.h
24 
25  Description: Main definitions for UR compression/decompression
26  library.
27 
28  Author: Grigoriy Starchenko
29 
30  ***************************************************************************
31 
32  PUBLIC DOMAIN NOTICE
33  National Center for Biotechnology Information
34 
35  This software/database is a "United States Government Work" under the
36  terms of the United States Copyright Act. It was written as part of
37  the author's official duties as a United States Government employee
38  and thus cannot be copyrighted. This software/database is freely
39  available to the public for use. The National Library of Medicine and
40  the U.S. Government have not placed any restriction on its use or
41  reproduction.
42 
43  Although all reasonable efforts have been taken to ensure the accuracy
44  and reliability of the software and data, the NLM and the U.S.
45  Government do not and cannot warrant the performance or results that
46  may be obtained by using this software or data. The NLM and the U.S.
47  Government disclaim all warranties, express or implied, including
48  warranties of performance, merchantability or fitness for any
49  particular purpose.
50 
51  Please cite the author in any work or product based on this material.
52 
53  ***************************************************************************
54 
55  Entry Points:
56 
57 
58  Modification History:
59 
60  $Log: nlmzip.h,v $
61  Revision 1.2 2001/05/09 01:17:48 kimelman
62  added FCI_read/close macros
63 
64  Revision 1.1 1998/05/15 19:05:16 kimelman
65  all old 'gzip' names changed to be suitable for library names.
66  prefix Nlmzip_ is now used for all of this local stuff.
67  interface headers changed their names, moving from artdb/ur to nlmzip
68 
69  Revision 1.9 1998/05/14 20:21:21 kimelman
70  ct_init --> Nlmzip_ct_init
71  added stream& AsnIo processing functions
72  makefile changed
73 
74  revision 1.8
75  date: 1998/04/09 20:29:29; author: grisha; state: Exp; lines: +5 -1
76  add code to switch off CRC check
77  ----------------------------
78  revision 1.7
79  date: 1996/04/19 20:38:14; author: grisha; state: Exp; lines: +3 -5
80  gbs006 commit changes for PubMed
81  ----------------------------
82  revision 1.6
83  date: 1995/11/02 17:51:58; author: grisha; state: Exp; lines: +7 -2
84  gbs002 add UrCompressedSize()
85  ----------------------------
86  revision 1.5
87  date: 1995/10/30 17:46:56; author: grisha; state: Exp; lines: +19 -18
88  gbs002 change types to core lib
89  ----------------------------
90  revision 1.4
91  date: 1995/08/23 10:32:19; author: grisha; state: Exp; lines: +5 -1
92  gbs002 update files
93  ----------------------------
94  revision 1.3
95  date: 1995/08/15 16:37:13; author: grisha; state: Exp; lines: +64 -7
96  gbs002 change return type for Nlmzip_UrCompress,Nlmzip_UrUncompress
97  ----------------------------
98  revision 1.2
99  date: 1995/08/15 16:14:13; author: grisha; state: Exp; lines: +1 -2
100  gbs002 add files for support compression
101  ----------------------------
102 
103  14 Aug 1995 - grisha - original written
104 
105  Bugs and restriction on use:
106 
107  Notes:
108 
109 *****************************************************************************/
110 
111 #include <corelib/ncbistd.hpp>
114 
115 /** @addtogroup CToolsBridge
116 *
117 * @{
118 */
119 
122 
123 
124 /***********************************************************************/
125 /* DEFINES */
126 /***********************************************************************/
127 
128 typedef enum {
133  NLMZIP_NOMEMORY = 4
135 
136 /***********************************************************************/
137 /* TYPEDEFS */
138 /***********************************************************************/
139 
140 typedef struct { /* stream processor descriptor */
142  Int4 (*proc_buf)(Pointer ptr, CharPtr buf, Int4 count);
143  Int4 (*close)(Pointer ptr, int commit);
144 } *fci_t;
145 
146 #define FCI_READ(_fci,_buf,_len) _fci->proc_buf(_fci->data,_buf,_len)
147 #define FCI_CLOSE(_fci,_commit) { _fci->close(_fci->data,_commit); MemFree(_fci); }
148 
149 
150 /***********************************************************************/
151 /* GLOBAL FUNCTIONS */
152 /***********************************************************************/
154 Nlmzip_Compress ( /* Compress input buffer and write to output */
155  const void*, /* pointer to source buffer (I) */
156  Int4, /* size of data in source buffer (I) */
157  void*, /* destination buffer (O) */
158  Int4, /* maximum size of destination buffer (I) */
159  Int4Ptr /* size of data that was written to destination (O) */
160  ); /* Return 0, if no error found */
161 
163 Nlmzip_Uncompress ( /* Uncompress input buffer and write to output */
164  const void*, /* pointer to source buffer (I) */
165  Int4, /* size of data in source buffer (I) */
166  void*, /* destination buffer (O) */
167  Int4, /* maximum size of destination buffer (I) */
168  Int4Ptr /* size of data that was written to destination (O) */
169  ); /* Return 0, if no error found */
170 
171 Int4
172 Nlmzip_UncompressedSize ( /* Return uncompressed block size */
173  VoidPtr, /* Input data (I) */
174  Int4 /* Input data size (I) */
175  );
176 
177 const char*
178 Nlmzip_ErrMsg ( /* Get error message for error code */
179  Int4 /* Error code */
180  );
181 
182 Boolean
183 Nlmzip_CrcMode ( /* Disable/enable CRC check */
184  Boolean
185  );
186 
188 fci_open ( /* create stream processor descriptor */
189  Pointer data, /* pointer do internal data structure */
190  /* buffer processor */
191  Int4 (*proc_buf) (Pointer ptr, CharPtr buf, Int4 count),
192  /* action to take on close - should free space taken by 'data' pointed object */
193  Int4 (*pclose)(Pointer ptr, int commit)
194  );
195 
196 /* creates cache on given stream. this object will gradually increase the size of caching
197  buffer from 1k to 'max_cache_size' bytes */
198 fci_t LIBCALL cacher_open(fci_t stream, int max_cache_size,int read);
199 
200 /* creates compressor lay on the stream */
201 fci_t LIBCALL compressor_open(fci_t stream, int max_buffer_size, int read);
202 
203 
204 
205 //////////////////////////////////////////////////////////////////////////////
206 //
207 // Wrapper functions that works with old Nlmzip and new methods from
208 // C++ Compression API
209 //
210 
211 //////////////////////////////////////////////////////////////////////////////
212 //
213 // We use our own format to store compressed data:
214 //
215 // -----------------------------------------------------------
216 // | magic (2) | method (1) | reserved (1) | compressed data |
217 // -----------------------------------------------------------
218 //
219 // magic - magic signature ('2f,9a'), different from zlib`s '1f,8b';
220 // method - used compression method;
221 // reserved - some bytes, just in case for possible future changes;
222 //
223 //
224 //////////////////////////////////////////////////////////////////////////////
225 
226 
227 /// Compress data in the buffer.
228 ///
229 /// Use specified method to.compress data.
230 ///
231 /// @param src_buf
232 /// Source buffer.
233 /// @param src_len
234 /// Size of data in source buffer.
235 /// @param dst_buf
236 /// Destination buffer.
237 /// @param dst_size
238 /// Size of destination buffer.
239 /// In some cases, small source data or bad compressed data for example,
240 /// it should be a little more then size of the source buffer.
241 /// @param dst_len
242 /// Size of compressed data in destination buffer.
243 /// @param method
244 /// Compression method, zip/deflate by default.
245 /// @sa
246 /// CT_DecompressBuffer, CCompression
247 /// @return
248 /// Return TRUE if operation was successfully or FALSE otherwise.
249 /// On success, 'dst_buf' contains compressed data of 'dst_len' size.
250 
251 bool CT_CompressBuffer(
252  const void* src_buf, size_t src_len,
253  void* dst_buf, size_t dst_size,
254  /* out */ size_t* dst_len,
257 );
258 
259 
260 /// Decompress data in the buffer.
261 ///
262 /// Automatically detects format of data, written by CT_CompressBuffer.
263 /// If it cannot recognize format, assumes that this is an NlMZIP.
264 ///
265 /// @note
266 /// The decompressor stops and returns TRUE, if it find logical
267 /// end in the compressed data, even not all compressed data was processed.
268 /// @param src_buf
269 /// Source buffer.
270 /// @param src_len
271 /// Size of data in source buffer.
272 /// @param dst_buf
273 /// Destination buffer.
274 /// It must be large enough to hold all of the uncompressed data for the operation to complete.
275 /// @param dst_size
276 /// Size of destination buffer.
277 /// @param dst_len
278 /// Size of decompressed data in destination buffer.
279 /// @sa
280 /// CT_CompressBuffer, CCompression
281 /// @return
282 /// Return TRUE if operation was successfully or FALSE otherwise.
283 /// On success, 'dst_buf' contains decompressed data of dst_len size.
284 
286  const void* src_buf, size_t src_len,
287  void* dst_buf, size_t dst_size,
288  /* out */ size_t* dst_len
289 );
290 
291 
292 
294 
295 /* @} */
296 
297 // Re-enable warnings
298 #ifdef __GNUC__ // if gcc or g++
299 # pragma GCC diagnostic pop
300 #endif //__GNUC__
301 
302 
303 #endif /* __nlmzip__ */
Include a standard set of the NCBI C++ Toolkit most basic headers.
int close(int fd)
Definition: connection.cpp:45
char data[12]
Definition: iconv.c:80
bool CT_DecompressBuffer(const void *src_buf, size_t src_len, void *dst_buf, size_t dst_size, size_t *dst_len)
Decompress data in the buffer.
#define BEGIN_CTRANSITION_SCOPE
Definition: ncbilcl.hpp:49
Nlmzip_rc_t
Definition: nlmzip.hpp:128
fci_t LIBCALL cacher_open(fci_t stream, int max_cache_size, int read)
Pointer data
Definition: nlmzip.hpp:141
#define CharPtr
Definition: ncbistd.hpp:125
#define Int4Ptr
Definition: ncbistd.hpp:180
bool CT_CompressBuffer(const void *src_buf, size_t src_len, void *dst_buf, size_t dst_size, size_t *dst_len, CCompressStream::EMethod method=CCompressStream::eZip, CCompression::ELevel level=CCompression::eLevel_Default)
Compress data in the buffer.
fci_t LIBCALL compressor_open(fci_t stream, int max_buffer_size, int read)
Boolean Nlmzip_CrcMode(Boolean)
Nlmzip_rc_t Nlmzip_Uncompress(const void *, Int4, void *, Int4, Int4Ptr)
BEGIN_CTRANSITION_SCOPE USING_NCBI_SCOPE
Definition: nlmzip.hpp:121
#define LIBCALL
Definition: ncbistd.hpp:297
Nlmzip_rc_t Nlmzip_Compress(const void *, Int4, void *, Int4, Int4Ptr)
#define VoidPtr
Definition: ncbistd.hpp:111
Int4 Nlmzip_UncompressedSize(VoidPtr, Int4)
const char * Nlmzip_ErrMsg(Int4)
#define END_CTRANSITION_SCOPE
Definition: ncbilcl.hpp:50
#define Pointer
Definition: ncbistd.hpp:114
fci_t LIBCALL fci_open(Pointer data, Int4(*proc_buf)(Pointer ptr, CharPtr buf, Int4 count), Int4(*pclose)(Pointer ptr, int commit))
@ NLMZIP_NOMEMORY
Definition: nlmzip.hpp:133
@ NLMZIP_BADCRC
Definition: nlmzip.hpp:131
@ NLMZIP_OKAY
Definition: nlmzip.hpp:129
@ NLMZIP_OUTSMALL
Definition: nlmzip.hpp:132
@ NLMZIP_INVALIDPARAM
Definition: nlmzip.hpp:130
EMethod
Compression/decompression methods.
Definition: stream_util.hpp:98
@ eZip
ZLIB (raw zip data / DEFLATE method)
ELevel
Compression level.
Definition: compress.hpp:142
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
char * buf
Uint1 Boolean
bool replacment for C
Definition: ncbi_std.h:94
#define count
C++ I/O stream wrappers to compress/decompress data on-the-fly.
Modified on Fri Sep 20 14:57:55 2024 by modify_doxy.py rev. 669887