/* * Print data for a given file */ static void _PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt) { char buf[4096]; size_t cnt; if (!filename) return; #ifdef HAVE_LIBZ AH->FH = gzopen(filename, "rb"); #else AH->FH = fopen(filename, PG_BINARY_R); #endif if (AH->FH == NULL) die_horribly(AH, modulename, "could not open data file for input\n"); while ((cnt = GZREAD(buf, 1, 4095, AH->FH)) > 0) { buf[cnt] = '\0'; ahwrite(buf, 1, cnt, AH); } if (GZCLOSE(AH->FH) != 0) die_horribly(AH, modulename, "could not close data file after reading\n"); }
/*------ * Called by dumper via archiver from within a data dump routine * As at V1.3, this is only called for COPY FROM dfata, and BLOB data *------ */ static size_t _WriteData(ArchiveHandle *AH, const void *data, size_t dLen) { /* Just send it to output */ ahwrite(data, 1, dLen, AH); return dLen; }
static void ReadDataFromArchiveNone(ArchiveHandle * AH, read_f* readF) { size_t cnt; char *buf; size_t buflen; buf = malloc(ZLIB_OUT_SIZE); if (buf == NULL) die_horribly(NULL, modulename, "out of memory\n"); buflen = ZLIB_OUT_SIZE; while ((cnt = readF(AH, &buf, &buflen))) { ahwrite(buf, 1, cnt, AH); } free(buf); }
static void ReadDataFromArchiveNone(ArchiveHandle *AH, ReadFunc readF) { size_t cnt; char *buf; size_t buflen; buf = pg_malloc(ZLIB_OUT_SIZE); buflen = ZLIB_OUT_SIZE; while ((cnt = readF(AH, &buf, &buflen))) { ahwrite(buf, 1, cnt, AH); } free(buf); }
static void ReadDataFromArchiveZlib(ArchiveHandle * AH, read_f* readF) { z_streamp zp; char *out; int res = Z_OK; size_t cnt; char *buf; size_t buflen; zp = (z_streamp) malloc(sizeof(z_stream)); if (zp == NULL) die_horribly(NULL, modulename, "out of memory\n"); zp->zalloc = Z_NULL; zp->zfree = Z_NULL; zp->opaque = Z_NULL; buf = malloc(ZLIB_IN_SIZE); if (buf == NULL) die_horribly(NULL, modulename, "out of memory\n"); buflen = ZLIB_IN_SIZE; out = malloc(ZLIB_OUT_SIZE + 1); if (out == NULL) die_horribly(NULL, modulename, "out of memory\n"); if (inflateInit(zp) != Z_OK) die_horribly(NULL, modulename, "could not initialize compression library: %s\n", zp->msg); /* no minimal chunk size for zlib */ while ((cnt = readF(AH, &buf, &buflen))) { zp->next_in = (void *)buf; zp->avail_in = cnt; while (zp->avail_in > 0) { zp->next_out = (void *)out; zp->avail_out = ZLIB_OUT_SIZE; res = inflate(zp, 0); if (res != Z_OK && res != Z_STREAM_END) die_horribly(AH, modulename, "could not uncompress data: %s\n", zp->msg); out[ZLIB_OUT_SIZE - zp->avail_out] = '\0'; ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH); } } zp->next_in = NULL; zp->avail_in = 0; while (res != Z_STREAM_END) { zp->next_out = (void *)out; zp->avail_out = ZLIB_OUT_SIZE; res = inflate(zp, 0); if (res != Z_OK && res != Z_STREAM_END) die_horribly(AH, modulename, "could not uncompress data: %s\n", zp->msg); out[ZLIB_OUT_SIZE - zp->avail_out] = '\0'; ahwrite(out, 1, ZLIB_OUT_SIZE - zp->avail_out, AH); } if (inflateEnd(zp) != Z_OK) die_horribly(AH, modulename, "could not close compression library: %s\n", zp->msg); free(buf); free(out); free(zp); }