Commit bf9aa490 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Refactor the pg_dump zlib code from pg_backup_custom.c to a separate file,

to make it easier to reuse that code. There is no user-visible changes.

This is in preparation for the patch to add a new archive format, a directory,
to perform a custom-like dump but with each table being dumped to a separate
file (that in turn is a prerequisite for parallel pg_dump). This also makes it
easier to add new compression methods in the future, and makes the
pg_backup_custom.c code easier to read, when the compression-related code is
factored out.

Joachim Wieland, with heavy editorialization by me.
parent 225f0aa3
...@@ -20,7 +20,7 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) ...@@ -20,7 +20,7 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_files.o pg_backup_null.o pg_backup_tar.o \ pg_backup_files.o pg_backup_null.o pg_backup_tar.o \
dumputils.o $(WIN32RES) dumputils.o compress_io.o $(WIN32RES)
KEYWRDOBJS = keywords.o kwlookup.o KEYWRDOBJS = keywords.o kwlookup.o
......
This diff is collapsed.
/*-------------------------------------------------------------------------
*
* compress_io.h
* Interface to compress_io.c routines
*
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* src/bin/pg_dump/compress_io.h
*
*-------------------------------------------------------------------------
*/
#ifndef __COMPRESS_IO__
#define __COMPRESS_IO__
#include "postgres_fe.h"
#include "pg_backup_archiver.h"
/* Initial buffer sizes used in zlib compression. */
#define ZLIB_OUT_SIZE 4096
#define ZLIB_IN_SIZE 4096
struct _CompressorState;
typedef enum
{
COMPR_ALG_NONE,
COMPR_ALG_LIBZ
} CompressionAlgorithm;
/* Prototype for callback function to WriteDataToArchive() */
typedef size_t (*WriteFunc)(ArchiveHandle *AH, const char *buf, size_t len);
/*
* Prototype for callback function to ReadDataFromArchive()
*
* ReadDataFromArchive will call the read function repeatedly, until it
* returns 0 to signal EOF. ReadDataFromArchive passes a buffer to read the
* data into in *buf, of length *buflen. If that's not big enough for the
* callback function, it can free() it and malloc() a new one, returning the
* new buffer and its size in *buf and *buflen.
*
* Returns the number of bytes read into *buf, or 0 on EOF.
*/
typedef size_t (*ReadFunc)(ArchiveHandle *AH, char **buf, size_t *buflen);
typedef struct _CompressorState
{
CompressionAlgorithm comprAlg;
WriteFunc writeF;
#ifdef HAVE_LIBZ
z_streamp zp;
char *zlibOut;
size_t zlibOutSize;
#endif
} CompressorState;
extern CompressorState *AllocateCompressor(int compression, WriteFunc writeF);
extern void ReadDataFromArchive(ArchiveHandle *AH, int compression,
ReadFunc readF);
extern size_t WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
const void *data, size_t dLen);
extern void EndCompressor(ArchiveHandle *AH, CompressorState *cs);
#endif
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#define GZCLOSE(fh) fclose(fh) #define GZCLOSE(fh) fclose(fh)
#define GZWRITE(p, s, n, fh) (fwrite(p, s, n, fh) * (s)) #define GZWRITE(p, s, n, fh) (fwrite(p, s, n, fh) * (s))
#define GZREAD(p, s, n, fh) fread(p, s, n, fh) #define GZREAD(p, s, n, fh) fread(p, s, n, fh)
/* this is just the redefinition of a libz constant */
#define Z_DEFAULT_COMPRESSION (-1) #define Z_DEFAULT_COMPRESSION (-1)
typedef struct _z_stream typedef struct _z_stream
...@@ -266,7 +267,11 @@ typedef struct _archiveHandle ...@@ -266,7 +267,11 @@ typedef struct _archiveHandle
DumpId maxDumpId; /* largest DumpId among all TOC entries */ DumpId maxDumpId; /* largest DumpId among all TOC entries */
struct _tocEntry *currToc; /* Used when dumping data */ struct _tocEntry *currToc; /* Used when dumping data */
int compression; /* Compression requested on open */ int compression; /* Compression requested on open
* Possible values for compression:
* -1 Z_DEFAULT_COMPRESSION
* 0 COMPRESSION_NONE
* 1-9 levels for gzip compression */
ArchiveMode mode; /* File mode - r or w */ ArchiveMode mode; /* File mode - r or w */
void *formatData; /* Header data specific to file format */ void *formatData; /* Header data specific to file format */
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment