1 module ncompress42; 2 3 /** 4 * Used for emulating file reads, as the library is a port of ncompress. 5 * The function must return the number of bytes read, 0 if EoF (or end of datasteam) has reached, 6 * or -1 on errors. 7 * rwCtxt can contain filenames if they're applicable. 8 */ 9 alias NCmpStreamReader = extern (C) int function(ubyte* bytes, size_t numBytes, void* rwCtxt); 10 /** 11 * Used for emulating file writes. 12 * It must return the number of files pushed, or -1 on error 13 */ 14 alias NCmpStreamWriter = extern (C) int function(const(ubyte)* bytes, size_t numBytes, void* rwCtxt); 15 16 /** 17 * Used for storing function pointers and other contextual stuff. 18 */ 19 struct NCompressCtxt 20 { 21 NCmpStreamReader reader; 22 NCmpStreamWriter writer; 23 void* rwCtxt; // context for the reader and writer 24 25 void* priv; 26 } 27 28 /** 29 * Error codes, mainly from decompression. 30 */ 31 enum NCompressError 32 { 33 NCMP_OK = 0, 34 35 NCMP_READ_ERROR, // an error from the reader 36 NCMP_WRITE_ERROR, // an error from the writer 37 38 NCMP_DATA_ERROR, // invalid compressed data format 39 NCMP_BITS_ERROR, // compressed with too large a bits parameter 40 NCMP_OTHER_ERROR, // some other internal error 41 } 42 43 extern (C): 44 /** 45 * Initialise for compression. 46 * Set the reader, writer and read-write context in 47 * the CompressCtxt struct. Then call initCompress() 48 * The bits parameter is only used when compressing. It sets the maximum 49 * size of a code word. The value must be in the range 9 to 16 or else 50 * zero to select the default of 16. 51 */ 52 void nInitCompress(NCompressCtxt* ctxt, int bits); 53 /** 54 * Initialise for decompression. 55 * Set the reader, writer and read-write context in 56 * the CompressCtxt struct. Then call initDecompress() 57 */ 58 void nInitDecompress(NCompressCtxt* ctxt); 59 ///Frees all buffers up. 60 void nFreeCompress(NCompressCtxt* ctxt); 61 ///Compresses the datasteam 62 NCompressError nCompress(NCompressCtxt* ctxt); 63 ///Decompresses the datastream 64 NCompressError nDecompress(NCompressCtxt* ctxt);