From 19b23eafe4d8039e30bc4f49a4c04ebea9e85cda Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Wed, 17 Apr 2019 01:32:08 +0200 Subject: Add saveToFd, saveToFilePointer and saveWithWriteCallback --- src/cc4group.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/cc4group.h') diff --git a/src/cc4group.h b/src/cc4group.h index dd5664a..91344d5 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -150,6 +150,13 @@ typedef bool (*CC4Group_ReadCallback)(const void** const data, size_t* const siz typedef bool (*CC4Group_ReadSetupCallback)(void* const arg); +// callback type for saveWithWriteCallback +// the callback needs to write the whole buffer (size bytes pointed to by data) to the desired place or copy it into it's own memory +// after the callback returns, the buffer will be overwritten +// the callback should return true on success and false on failure +typedef bool (*CC4Group_WriteCallback)(const void* const data, size_t const size, void* const arg); + + // this is the main API struct of cc4group // it contains all available methods and constants typedef struct { @@ -230,6 +237,23 @@ typedef struct { // be careful, any existing file will be overwritten in-place. if any error occurs after opening the target file (e.g. out of memory, a program or system crash), the previous contents will be lost bool (*saveOverwrite)(CC4Group* const this, const char* const path); + // saves the compressed group file by writing it to the file descriptor + // the file descriptor must have been opened with write access and must be in blocking mode (should be default if O_NONBLOCK is not specified) + // also be aware that the file must be opened with binary mode on windows + bool (*saveToFd)(CC4Group* const this, int fd); + + // saves the compressed group file by writing it to the FILE* + // the file must have been opened with read access; also be aware that the file must be opened with binary mode on windows + bool (*saveToFilePointer)(CC4Group* const this, FILE* file); + + // saves the compressed group to a custom storage with the help of a writeCallback + // the callback will receive the custom arg argument as its arg argument at each call + // bufferSize denotes the maximum buffer size that the callback wants to receive + // be aware that cc4group will internally allocate a buffer of the given size + // bufferSize may be 0 to use the default of 1 MB + // writeCallback will be called whenever the internal buffer (of bufferSize) is full, and finally when the saving has finished with a smaller size to store the remaining data + bool (*saveWithWriteCallback)(CC4Group* const this, CC4Group_WriteCallback const writeCallback, void* const arg, size_t const bufferSize); + // extraction to disk -- cgit v1.2.3-54-g00ecf