1/*-------------------------------------------------------------------------
4 * Interface to compress_io.c routines
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/bin/pg_dump/compress_io.h
12 *-------------------------------------------------------------------------
15#ifndef __COMPRESS_IO__
16#define __COMPRESS_IO__
21 * Default size used for IO buffers
23 * When changing this value, it's necessary to check the relevant test cases
24 * still exercise all the branches. This applies especially if the value is
25 * increased, in which case the overflow buffer may not be needed.
27 #define DEFAULT_IO_BUFFER_SIZE 4096
32 * Prototype for callback function used in writeData()
37 * Prototype for callback function used in readData()
39 * readData will call the read function repeatedly, until it returns 0 to signal
40 * EOF. readData passes a buffer to read the data into in *buf, of length
41 * *buflen. If that's not big enough for the callback function, it can free() it
42 * and malloc() a new one, returning the new buffer and its size in *buf and
45 * Returns the number of bytes read into *buf, or 0 on EOF.
53 * Read all compressed data from the input stream (via readF) and print it
59 * Compress and write data to the output stream (via writeF).
62 const void *
data,
size_t dLen);
65 * End compression and flush internal buffers if any.
70 * Callback function to read from an already processed input stream
75 * Callback function to write an already processed chunk of data.
80 * Compression specification for this state.
85 * Private data to be used by the compressor.
96 * Compress File Handle
103 * Open a file in mode.
105 * Pass either 'path' or 'fd' depending on whether a file path or a file
106 * descriptor is available. 'mode' can be one of 'r', 'rb', 'w', 'wb',
107 * 'a', and 'ab'. Requires an already initialized CompressFileHandle.
109 * Returns true on success and false on error.
115 * Open a file for writing.
117 * 'mode' can be one of 'w', 'wb', 'a', and 'ab'. Requires an already
118 * initialized CompressFileHandle.
120 * Returns true on success and false on error.
126 * Read up to 'size' bytes of data from the file and store them into
129 * Returns number of bytes read (this might be less than 'size' if EOF was
130 * reached). Exits via pg_fatal for all error conditions.
136 * Write 'size' bytes of data into the file from 'ptr'.
138 * Returns nothing, exits via pg_fatal for all error conditions.
144 * Read at most size - 1 characters from the compress file handle into
147 * Stop if an EOF or a newline is found first. 's' is always null
148 * terminated and contains the newline if it was found.
150 * Returns 's' on success, and NULL on error or when end of file occurs
151 * while no characters have been read.
156 * Read the next character from the compress file handle as 'unsigned
157 * char' cast into 'int'.
159 * Returns the character read on success and throws an internal error
160 * otherwise. It treats EOF as error.
165 * Test if EOF is reached in the compress file handle.
167 * Returns true if it is reached.
172 * Close an open file handle.
174 * Returns true on success and false on error.
179 * Get a pointer to a string that describes an error that occurred during
180 * a compress file handle operation.
185 * Compression specification for this file handle.
190 * Private data to be used by the compressor.
196 * Initialize a compress file handle with the requested compression.
201 * Initialize a compress file stream. Infer the compression algorithm
202 * from 'path', either by examining its suffix or by appending the supported
203 * suffixes in 'path'.
size_t(* ReadFunc)(ArchiveHandle *AH, char **buf, size_t *buflen)
bool EndCompressFileHandle(CompressFileHandle *CFH)
CompressorState * AllocateCompressor(const pg_compress_specification compression_spec, ReadFunc readF, WriteFunc writeF)
CompressFileHandle * InitDiscoverCompressFileHandle(const char *path, const char *mode)
char * supports_compression(const pg_compress_specification compression_spec)
void(* WriteFunc)(ArchiveHandle *AH, const char *buf, size_t len)
void EndCompressor(ArchiveHandle *AH, CompressorState *cs)
CompressFileHandle * InitCompressFileHandle(const pg_compress_specification compression_spec)
static PgChecksumMode mode
static int fd(const char *x, int i)
bool(* open_write_func)(const char *path, const char *mode, CompressFileHandle *CFH)
int(* getc_func)(CompressFileHandle *CFH)
bool(* eof_func)(CompressFileHandle *CFH)
size_t(* read_func)(void *ptr, size_t size, CompressFileHandle *CFH)
bool(* open_func)(const char *path, int fd, const char *mode, CompressFileHandle *CFH)
pg_compress_specification compression_spec
bool(* close_func)(CompressFileHandle *CFH)
void(* write_func)(const void *ptr, size_t size, CompressFileHandle *CFH)
void(* readData)(ArchiveHandle *AH, CompressorState *cs)
pg_compress_specification compression_spec
void(* end)(ArchiveHandle *AH, CompressorState *cs)
void(* writeData)(ArchiveHandle *AH, CompressorState *cs, const void *data, size_t dLen)