From 9103fb5b961817d1a91248632b4cedfec770b198 Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Sat, 16 Mar 2019 03:50:28 +0100 Subject: Add openFd, openFilePointer and openWithReadCallback methods --- src/cc4group.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/cc4group.h') diff --git a/src/cc4group.h b/src/cc4group.h index 16c684a..a63d995 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -10,6 +10,7 @@ extern "C" { #include #include #include +#include typedef struct { const char* fileName; @@ -31,6 +32,11 @@ typedef struct { } CC4Group_CleanupJob; typedef void* (*CC4Group_TmpMemoryStrategy)(CC4Group* const this, const size_t size, CC4Group_CleanupJob* cleanupJob); +// the callback has to store a pointer to the newly read data in data, as well as the amount of read data in size +// the callback must return true if the end of data is reached or any read error happens and false otherwise +// the pointer passed in will be handled as specified with the corresponding MemoryManagement +typedef bool (*CC4Group_ReadCallback)(const uint8_t** const data, size_t* const size, void* const arg); + typedef struct { CC4Group* (*new)(void); bool (*create)(CC4Group* const this); @@ -42,7 +48,20 @@ typedef struct { // opens a group that is stored entirely in memory // only open an in-memory group on a frehsly created group object - bool (*openMemory)(CC4Group* const this, const uint8_t* const groupData, size_t const size); + // see the description of MemoryManagement to know if and when data has to be freed by the caller + // if the lazy mode is not used, the data can be freed immediately after this function returns + bool (*openMemory)(CC4Group* const this, const uint8_t* const groupData, size_t const size, int const memoryManagement); + + // opens a group through a file descriptor + // the file descriptor must have been opened with read access + bool (*openFd)(CC4Group* const this, int fd); + + // opens a group through a FILE* + // the file must have been opened with read access + bool (*openFilePointer)(CC4Group* const this, FILE* fd); + + // opens a group and calls the callback to get the group data + bool (*openWithReadCallback)(CC4Group* const this, CC4Group_ReadCallback const callback, void* const callbackArg, int const memoryManagement); bool (*save)(CC4Group* const this, const char* const path); bool (*saveOverwrite)(CC4Group* const this, const char* const path); -- cgit v1.2.3-54-g00ecf