Header And Logo

PostgreSQL
| The world's most advanced open source database.

compress_io.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * compress_io.h
00004  *   Interface to compress_io.c routines
00005  *
00006  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00007  * Portions Copyright (c) 1994, Regents of the University of California
00008  *
00009  * IDENTIFICATION
00010  *     src/bin/pg_dump/compress_io.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 
00015 #ifndef __COMPRESS_IO__
00016 #define __COMPRESS_IO__
00017 
00018 #include "postgres_fe.h"
00019 #include "pg_backup_archiver.h"
00020 
00021 /* Initial buffer sizes used in zlib compression. */
00022 #define ZLIB_OUT_SIZE   4096
00023 #define ZLIB_IN_SIZE    4096
00024 
00025 typedef enum
00026 {
00027     COMPR_ALG_NONE,
00028     COMPR_ALG_LIBZ
00029 } CompressionAlgorithm;
00030 
00031 /* Prototype for callback function to WriteDataToArchive() */
00032 typedef size_t (*WriteFunc) (ArchiveHandle *AH, const char *buf, size_t len);
00033 
00034 /*
00035  * Prototype for callback function to ReadDataFromArchive()
00036  *
00037  * ReadDataFromArchive will call the read function repeatedly, until it
00038  * returns 0 to signal EOF. ReadDataFromArchive passes a buffer to read the
00039  * data into in *buf, of length *buflen. If that's not big enough for the
00040  * callback function, it can free() it and malloc() a new one, returning the
00041  * new buffer and its size in *buf and *buflen.
00042  *
00043  * Returns the number of bytes read into *buf, or 0 on EOF.
00044  */
00045 typedef size_t (*ReadFunc) (ArchiveHandle *AH, char **buf, size_t *buflen);
00046 
00047 /* struct definition appears in compress_io.c */
00048 typedef struct CompressorState CompressorState;
00049 
00050 extern CompressorState *AllocateCompressor(int compression, WriteFunc writeF);
00051 extern void ReadDataFromArchive(ArchiveHandle *AH, int compression,
00052                     ReadFunc readF);
00053 extern size_t WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
00054                    const void *data, size_t dLen);
00055 extern void EndCompressor(ArchiveHandle *AH, CompressorState *cs);
00056 
00057 
00058 typedef struct cfp cfp;
00059 
00060 extern cfp *cfopen(const char *path, const char *mode, int compression);
00061 extern cfp *cfopen_read(const char *path, const char *mode);
00062 extern cfp *cfopen_write(const char *path, const char *mode, int compression);
00063 extern int  cfread(void *ptr, int size, cfp *fp);
00064 extern int  cfwrite(const void *ptr, int size, cfp *fp);
00065 extern int  cfgetc(cfp *fp);
00066 extern char *cfgets(cfp *fp, char *buf, int len);
00067 extern int  cfclose(cfp *fp);
00068 extern int  cfeof(cfp *fp);
00069 
00070 #endif