27typedef struct GzipCompressorState
42 const void *
data,
size_t dLen);
48 GzipCompressorState *gzipcs;
51 gzipcs = (GzipCompressorState *)
pg_malloc0(
sizeof(GzipCompressorState));
52 zp = gzipcs->zp = (z_streamp)
pg_malloc(
sizeof(z_stream));
63 gzipcs->outbuf =
pg_malloc(gzipcs->outsize + 1);
69 pg_fatal(
"could not initialize compression library: %s", zp->msg);
72 zp->next_out = gzipcs->outbuf;
73 zp->avail_out = gzipcs->outsize;
82 GzipCompressorState *gzipcs = (GzipCompressorState *) cs->
private_data;
90 DeflateCompressorCommon(AH, cs,
true);
92 if (deflateEnd(zp) != Z_OK)
93 pg_fatal(
"could not close compression stream: %s", zp->msg);
104 GzipCompressorState *gzipcs = (GzipCompressorState *) cs->
private_data;
105 z_streamp zp = gzipcs->zp;
106 void *out = gzipcs->outbuf;
109 while (gzipcs->zp->avail_in != 0 || flush)
111 res = deflate(zp, flush ? Z_FINISH : Z_NO_FLUSH);
112 if (
res == Z_STREAM_ERROR)
113 pg_fatal(
"could not compress data: %s", zp->msg);
114 if ((flush && (zp->avail_out < gzipcs->outsize))
115 || (zp->avail_out == 0)
116 || (zp->avail_in != 0)
124 if (zp->avail_out < gzipcs->outsize)
130 size_t len = gzipcs->outsize - zp->avail_out;
135 zp->avail_out = gzipcs->outsize;
138 if (
res == Z_STREAM_END)
148 DeflateCompressorEnd(AH, cs);
153 const void *
data,
size_t dLen)
155 GzipCompressorState *gzipcs = (GzipCompressorState *) cs->
private_data;
157 gzipcs->zp->next_in =
data;
158 gzipcs->zp->avail_in = dLen;
159 DeflateCompressorCommon(AH, cs,
false);
172 zp = (z_streamp)
pg_malloc(
sizeof(z_stream));
182 if (inflateInit(zp) != Z_OK)
183 pg_fatal(
"could not initialize compression library: %s",
187 while ((cnt = cs->
readF(AH, &
buf, &buflen)))
189 zp->next_in = (
void *)
buf;
192 while (zp->avail_in > 0)
194 zp->next_out = (
void *) out;
197 res = inflate(zp, 0);
198 if (
res != Z_OK &&
res != Z_STREAM_END)
199 pg_fatal(
"could not uncompress data: %s", zp->msg);
208 while (
res != Z_STREAM_END)
210 zp->next_out = (
void *) out;
212 res = inflate(zp, 0);
213 if (
res != Z_OK &&
res != Z_STREAM_END)
214 pg_fatal(
"could not uncompress data: %s", zp->msg);
220 if (inflateEnd(zp) != Z_OK)
221 pg_fatal(
"could not close compression library: %s", zp->msg);
233 cs->
readData = ReadDataFromArchiveGzip;
235 cs->
end = EndCompressorGzip;
245 DeflateCompressorInit(cs);
260 gzret = gzread(gzfp, ptr,
size);
261 if (gzret <= 0 && !gzeof(gzfp))
264 const char *
errmsg = gzerror(gzfp, &errnum);
266 pg_fatal(
"could not read from input file: %s",
271 *rsize = (size_t) gzret;
281 return gzwrite(gzfp, ptr,
size) > 0;
295 pg_fatal(
"could not read from input file: %m");
297 pg_fatal(
"could not read from input file: end of file");
308 return gzgets(gzfp, ptr,
size);
318 return gzclose(gzfp) == Z_OK;
326 return gzeof(gzfp) == 1;
336 errmsg = gzerror(gzfp, &errnum);
337 if (errnum == Z_ERRNO)
347 char mode_compression[32];
354 snprintf(mode_compression,
sizeof(mode_compression),
"%s%d",
358 strcpy(mode_compression,
mode);
361 gzfp = gzdopen(dup(
fd), mode_compression);
363 gzfp = gzopen(path, mode_compression);
413 pg_fatal(
"this build does not support compression with %s",
"gzip");
420 pg_fatal(
"this build does not support compression with %s",
"gzip");
#define Assert(condition)
void InitCompressFileHandleGzip(CompressFileHandle *CFH, const pg_compress_specification compression_spec)
void InitCompressorGzip(CompressorState *cs, const pg_compress_specification compression_spec)
#define DEFAULT_IO_BUFFER_SIZE
static void PGresult * res
int errmsg(const char *fmt,...)
void * pg_malloc(size_t size)
void * pg_malloc0(size_t size)
void ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
static PgChecksumMode mode
static int fd(const char *x, int i)
char * psprintf(const char *fmt,...)
static pg_noinline void Size size
char *(* gets_func)(char *s, int size, CompressFileHandle *CFH)
bool(* open_write_func)(const char *path, const char *mode, CompressFileHandle *CFH)
bool(* write_func)(const void *ptr, size_t size, struct CompressFileHandle *CFH)
int(* getc_func)(CompressFileHandle *CFH)
const char *(* get_error_func)(CompressFileHandle *CFH)
bool(* eof_func)(CompressFileHandle *CFH)
bool(* open_func)(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
pg_compress_specification compression_spec
bool(* close_func)(CompressFileHandle *CFH)
bool(* read_func)(void *ptr, size_t size, size_t *rsize, CompressFileHandle *CFH)
void(* readData)(ArchiveHandle *AH, CompressorState *cs)
pg_compress_specification compression_spec
void(* end)(ArchiveHandle *AH, CompressorState *cs)
void(* writeData)(ArchiveHandle *AH, CompressorState *cs, const void *data, size_t dLen)