| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * compress_io.h |
| 4 | * Interface to compress_io.c routines |
| 5 | * |
| 6 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 7 | * Portions Copyright (c) 1994, Regents of the University of California |
| 8 | * |
| 9 | * IDENTIFICATION |
| 10 | * src/bin/pg_dump/compress_io.h |
| 11 | * |
| 12 | *------------------------------------------------------------------------- |
| 13 | */ |
| 14 | |
| 15 | #ifndef __COMPRESS_IO__ |
| 16 | #define __COMPRESS_IO__ |
| 17 | |
| 18 | #include "pg_backup_archiver.h" |
| 19 | |
| 20 | /* Initial buffer sizes used in zlib compression. */ |
| 21 | #define ZLIB_OUT_SIZE 4096 |
| 22 | #define ZLIB_IN_SIZE 4096 |
| 23 | |
| 24 | typedef enum |
| 25 | { |
| 26 | COMPR_ALG_NONE, |
| 27 | COMPR_ALG_LIBZ |
| 28 | } CompressionAlgorithm; |
| 29 | |
| 30 | /* Prototype for callback function to WriteDataToArchive() */ |
| 31 | typedef void (*WriteFunc) (ArchiveHandle *AH, const char *buf, size_t len); |
| 32 | |
| 33 | /* |
| 34 | * Prototype for callback function to ReadDataFromArchive() |
| 35 | * |
| 36 | * ReadDataFromArchive will call the read function repeatedly, until it |
| 37 | * returns 0 to signal EOF. ReadDataFromArchive passes a buffer to read the |
| 38 | * data into in *buf, of length *buflen. If that's not big enough for the |
| 39 | * callback function, it can free() it and malloc() a new one, returning the |
| 40 | * new buffer and its size in *buf and *buflen. |
| 41 | * |
| 42 | * Returns the number of bytes read into *buf, or 0 on EOF. |
| 43 | */ |
| 44 | typedef size_t (*ReadFunc) (ArchiveHandle *AH, char **buf, size_t *buflen); |
| 45 | |
| 46 | /* struct definition appears in compress_io.c */ |
| 47 | typedef struct CompressorState CompressorState; |
| 48 | |
| 49 | extern CompressorState *AllocateCompressor(int compression, WriteFunc writeF); |
| 50 | extern void ReadDataFromArchive(ArchiveHandle *AH, int compression, |
| 51 | ReadFunc readF); |
| 52 | extern void WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs, |
| 53 | const void *data, size_t dLen); |
| 54 | extern void EndCompressor(ArchiveHandle *AH, CompressorState *cs); |
| 55 | |
| 56 | |
| 57 | typedef struct cfp cfp; |
| 58 | |
| 59 | extern cfp *cfopen(const char *path, const char *mode, int compression); |
| 60 | extern cfp *cfopen_read(const char *path, const char *mode); |
| 61 | extern cfp *cfopen_write(const char *path, const char *mode, int compression); |
| 62 | extern int cfread(void *ptr, int size, cfp *fp); |
| 63 | extern int cfwrite(const void *ptr, int size, cfp *fp); |
| 64 | extern int cfgetc(cfp *fp); |
| 65 | extern char *cfgets(cfp *fp, char *buf, int len); |
| 66 | extern int cfclose(cfp *fp); |
| 67 | extern int cfeof(cfp *fp); |
| 68 | extern const char *get_cfp_error(cfp *fp); |
| 69 | |
| 70 | #endif |
| 71 | |