MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndbzio.h
1 /*
2  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 /*
19  This library has been brought into the 21st century.
20  - Magnus BlĂ„udd
21 */
22 
23 /*
24  This libary has been modified for use by the MySQL Archive Engine.
25  -Brian Aker
26 */
27 
28 /* zlib.h -- interface of the 'zlib' general purpose compression library
29  version 1.2.3, July 18th, 2005
30 
31  Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
32 
33  This software is provided 'as-is', without any express or implied
34  warranty. In no event will the authors be held liable for any damages
35  arising from the use of this software.
36 
37  Permission is granted to anyone to use this software for any purpose,
38  including commercial applications, and to alter it and redistribute it
39  freely, subject to the following restrictions:
40 
41  1. The origin of this software must not be misrepresented; you must not
42  claim that you wrote the original software. If you use this software
43  in a product, an acknowledgment in the product documentation would be
44  appreciated but is not required.
45  2. Altered source versions must be plainly marked as such, and must not be
46  misrepresented as being the original software.
47  3. This notice may not be removed or altered from any source distribution.
48 
49  Jean-loup Gailly Mark Adler
50  jloup@gzip.org madler@alumni.caltech.edu
51 
52 
53  The data format used by the zlib library is described by RFCs (Request for
54  Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
55  (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
56 */
57 
58 #include <zlib.h>
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 size_t ndbz_inflate_mem_size();
65 size_t ndbz_deflate_mem_size();
67  size_t size;
68  size_t mfree;
69  char *mem;
70 };
71 
72 typedef struct ndbzio_stream {
73  z_stream stream;
74  int z_err; /* error code for last stream operation */
75  int z_eof; /* set if end of input file */
76  File file; /* .gz file */
77  Byte *inbuf; /* input buffer */
78  Byte *outbuf; /* output buffer */
79  uLong crc; /* crc32 of uncompressed data */
80  char *msg; /* error message */
81  int transparent; /* 1 if input file is not a .gz file */
82  char mode; /* 'w' or 'r' */
83  char bufalloced; /* true if ndbzio allocated buffers */
84  my_off_t start; /* start of compressed data in file (header skipped) */
85  my_off_t in; /* bytes into deflate or inflate */
86  my_off_t out; /* bytes out of deflate or inflate */
87  int back; /* one character push-back */
88  int last; /* true if push-back is last character */
89  unsigned char version; /* Version */
90  unsigned char minor_version; /* Version */
91  unsigned int block_size; /* Block Size */
92  unsigned long long check_point; /* Last position we checked */
93  unsigned long long forced_flushes; /* Forced Flushes */
94  unsigned long long rows; /* rows */
95  unsigned long long auto_increment; /* auto increment field */
96  unsigned int longest_row; /* Longest row */
97  unsigned int shortest_row; /* Shortest row */
98  unsigned char dirty; /* State of file */
99  unsigned int frm_start_pos; /* Position for start of FRM */
100  unsigned int frm_length; /* Position for start of FRM */
101  unsigned int comment_start_pos; /* Position for start of comment */
102  unsigned int comment_length; /* Position for start of comment */
103 } ndbzio_stream;
104 
105 /* Return the size in bytes used for reading */
106 size_t ndbz_bufsize_read(void);
107 
108 /* Return the size in bytes used for writing */
109 size_t ndbz_bufsize_write(void);
110 
111  /* basic functions */
112 extern int ndbzopen(ndbzio_stream *s, const char *path, int Flags);
113 /*
114  Opens a gzip (.gz) file for reading or writing. The mode parameter
115  is as in fopen ("rb" or "wb") but can also include a compression level
116  ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
117  Huffman only compression as in "wb1h", or 'R' for run-length encoding
118  as in "wb1R". (See the description of deflateInit2 for more information
119  about the strategy parameter.)
120 
121  ndbzopen can be used to read a file which is not in gzip format; in this
122  case gzread will directly read from the file without decompression.
123 
124  ndbzopen returns NULL if the file could not be opened or if there was
125  insufficient memory to allocate the (de)compression state; errno
126  can be checked to distinguish the two cases (if errno is zero, the
127  zlib error is Z_MEM_ERROR). */
128 
129 int ndbzdopen(ndbzio_stream *s, File fd, int Flags);
130 /*
131  ndbzdopen() associates a ndbzio_stream with the file descriptor fd. File
132  descriptors are obtained from calls like open, dup, creat, pipe or
133  fileno (in the file has been previously opened with fopen).
134  The mode parameter is as in ndbzopen.
135  The next call of gzclose on the returned ndbzio_stream will also close the
136  file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
137  descriptor fd. If you want to keep fd open, use ndbzdopen(dup(fd), mode).
138  ndbzdopen returns NULL if there was insufficient memory to allocate
139  the (de)compression state.
140 */
141 
142 
143 extern unsigned int ndbzread (ndbzio_stream *s, voidp buf,
144  unsigned int len, int *error);
145 /*
146  Reads the given number of uncompressed bytes from the compressed file.
147  If the input file was not in gzip format, gzread copies the given number
148  of bytes into the buffer.
149  gzread returns the number of uncompressed bytes actually read (0 for
150  end of file, -1 for error). */
151 
152 extern unsigned int ndbzwrite (ndbzio_stream *s, const void* buf,
153  unsigned int len);
154 /*
155  Writes the given number of uncompressed bytes into the compressed file.
156  ndbzwrite returns the number of uncompressed bytes actually written
157  (0 in case of error).
158 */
159 
160 
161 extern int ndbzflush(ndbzio_stream *file, int flush);
162 /*
163  Flushes all pending output into the compressed file. The parameter
164  flush is as in the deflate() function. The return value is the zlib
165  error number (see function gzerror below). gzflush returns Z_OK if
166  the flush parameter is Z_FINISH and all output could be flushed.
167  gzflush should be called only when strictly necessary because it can
168  degrade compression.
169 */
170 
171 extern my_off_t ndbzseek (ndbzio_stream *file,
172  my_off_t offset, int whence);
173 /*
174  Sets the starting position for the next gzread or gzwrite on the
175  given compressed file. The offset represents a number of bytes in the
176  uncompressed data stream. The whence parameter is defined as in lseek(2);
177  the value SEEK_END is not supported.
178  If the file is opened for reading, this function is emulated but can be
179  extremely slow. If the file is opened for writing, only forward seeks are
180  supported; gzseek then compresses a sequence of zeroes up to the new
181  starting position.
182 
183  gzseek returns the resulting offset location as measured in bytes from
184  the beginning of the uncompressed stream, or -1 in case of error, in
185  particular if the file is opened for writing and the new starting position
186  would be before the current position.
187 */
188 
189 extern int ndbzrewind(ndbzio_stream *file);
190 /*
191  Rewinds the given file. This function is supported only for reading.
192 
193  gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
194 */
195 
196 extern my_off_t ndbztell(ndbzio_stream *file);
197 /*
198  Returns the starting position for the next gzread or gzwrite on the
199  given compressed file. This position represents a number of bytes in the
200  uncompressed data stream.
201 
202  gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
203 */
204 
205 extern int ndbzclose(ndbzio_stream *file);
206 /*
207  Flushes all pending output if necessary, closes the compressed file
208  and deallocates all the (de)compression state. The return value is the zlib
209  error number (see function gzerror below).
210 */
211 
212 /*
213  Return file size of the open ndbzio_stream
214 */
215 extern int ndbz_file_size(ndbzio_stream *file, size_t *size);
216 
217 #ifdef __cplusplus
218 }
219 #endif