36typedef struct GzipCompressorState
51 const void *
data,
size_t dLen);
57 GzipCompressorState *gzipcs;
60 gzipcs = (GzipCompressorState *)
pg_malloc0(
sizeof(GzipCompressorState));
61 zp = gzipcs->zp = (z_streamp)
pg_malloc(
sizeof(z_stream));
72 gzipcs->outbuf =
pg_malloc(gzipcs->outsize + 1);
78 pg_fatal(
"could not initialize compression library: %s", zp->msg);
81 zp->next_out = gzipcs->outbuf;
82 zp->avail_out = gzipcs->outsize;
91 GzipCompressorState *gzipcs = (GzipCompressorState *) cs->
private_data;
99 DeflateCompressorCommon(AH, cs,
true);
101 if (deflateEnd(zp) != Z_OK)
102 pg_fatal(
"could not close compression stream: %s", zp->msg);
113 GzipCompressorState *gzipcs = (GzipCompressorState *) cs->
private_data;
114 z_streamp zp = gzipcs->zp;
115 void *out = gzipcs->outbuf;
118 while (gzipcs->zp->avail_in != 0 || flush)
120 res = deflate(zp, flush ? Z_FINISH : Z_NO_FLUSH);
121 if (res == Z_STREAM_ERROR)
122 pg_fatal(
"could not compress data: %s", zp->msg);
123 if ((flush && (zp->avail_out < gzipcs->outsize))
124 || (zp->avail_out == 0)
125 || (zp->avail_in != 0)
133 if (zp->avail_out < gzipcs->outsize)
139 size_t len = gzipcs->outsize - zp->avail_out;
144 zp->avail_out = gzipcs->outsize;
147 if (res == Z_STREAM_END)
157 DeflateCompressorEnd(AH, cs);
162 const void *
data,
size_t dLen)
164 GzipCompressorState *gzipcs = (GzipCompressorState *) cs->
private_data;
166 gzipcs->zp->next_in =
data;
167 gzipcs->zp->avail_in = dLen;
168 DeflateCompressorCommon(AH, cs,
false);
181 zp = (z_streamp)
pg_malloc(
sizeof(z_stream));
191 if (inflateInit(zp) != Z_OK)
192 pg_fatal(
"could not initialize compression library: %s",
196 while ((cnt = cs->
readF(AH, &
buf, &buflen)))
198 zp->next_in = (
void *)
buf;
201 while (zp->avail_in > 0)
203 zp->next_out = (
void *) out;
206 res = inflate(zp, 0);
207 if (res != Z_OK && res != Z_STREAM_END)
208 pg_fatal(
"could not uncompress data: %s", zp->msg);
217 while (res != Z_STREAM_END)
219 zp->next_out = (
void *) out;
221 res = inflate(zp, 0);
222 if (res != Z_OK && res != Z_STREAM_END)
223 pg_fatal(
"could not uncompress data: %s", zp->msg);
229 if (inflateEnd(zp) != Z_OK)
230 pg_fatal(
"could not close compression library: %s", zp->msg);
242 cs->
readData = ReadDataFromArchiveGzip;
244 cs->
end = EndCompressorGzip;
254 DeflateCompressorInit(cs);
273 gzret = gzread(gzfp, ptr, size);
285 if (gzret == 0 && gzeof(gzfp))
288 errmsg = gzerror(gzfp, &errnum);
290 pg_fatal(
"could not read from input file: %s",
294 return (
size_t) gzret;
304 if (gzwrite(gzfp, ptr, size) != size)
306 errmsg = gzerror(gzfp, &errnum);
307 pg_fatal(
"could not write to file: %s",
323 pg_fatal(
"could not read from input file: %m");
325 pg_fatal(
"could not read from input file: end of file");
336 return gzgets(gzfp, ptr, size);
346 return gzclose(gzfp) == Z_OK;
354 return gzeof(gzfp) == 1;
364 errmsg = gzerror(gzfp, &errnum);
365 if (errnum == Z_ERRNO)
375 char mode_compression[32];
382 snprintf(mode_compression,
sizeof(mode_compression),
"%s%d",
386 strcpy(mode_compression,
mode);
389 gzfp = gzdopen(dup(
fd), mode_compression);
391 gzfp = gzopen(path, mode_compression);
441 pg_fatal(
"this build does not support compression with %s",
"gzip");
448 pg_fatal(
"this build does not support compression with %s",
"gzip");
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
int errmsg(const char *fmt,...)
void * pg_malloc(size_t size)
void * pg_malloc0(size_t size)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
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,...)
char *(* gets_func)(char *s, int size, CompressFileHandle *CFH)
bool(* open_write_func)(const char *path, const char *mode, CompressFileHandle *CFH)
int(* getc_func)(CompressFileHandle *CFH)
const char *(* get_error_func)(CompressFileHandle *CFH)
bool(* eof_func)(CompressFileHandle *CFH)
size_t(* read_func)(void *ptr, size_t size, 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)
void(* write_func)(const void *ptr, size_t size, 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)