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
24typedef enum
25{
26 COMPR_ALG_NONE,
27 COMPR_ALG_LIBZ
28} CompressionAlgorithm;
29
30/* Prototype for callback function to WriteDataToArchive() */
31typedef 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 */
44typedef size_t (*ReadFunc) (ArchiveHandle *AH, char **buf, size_t *buflen);
45
46/* struct definition appears in compress_io.c */
47typedef struct CompressorState CompressorState;
48
49extern CompressorState *AllocateCompressor(int compression, WriteFunc writeF);
50extern void ReadDataFromArchive(ArchiveHandle *AH, int compression,
51 ReadFunc readF);
52extern void WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
53 const void *data, size_t dLen);
54extern void EndCompressor(ArchiveHandle *AH, CompressorState *cs);
55
56
57typedef struct cfp cfp;
58
59extern cfp *cfopen(const char *path, const char *mode, int compression);
60extern cfp *cfopen_read(const char *path, const char *mode);
61extern cfp *cfopen_write(const char *path, const char *mode, int compression);
62extern int cfread(void *ptr, int size, cfp *fp);
63extern int cfwrite(const void *ptr, int size, cfp *fp);
64extern int cfgetc(cfp *fp);
65extern char *cfgets(cfp *fp, char *buf, int len);
66extern int cfclose(cfp *fp);
67extern int cfeof(cfp *fp);
68extern const char *get_cfp_error(cfp *fp);
69
70#endif
71