zlibio.h
 1  #ifndef     __ZLIB_IO_H_
 2  #define     __ZLIB_IO_H_
 3  
 4  
 5  // Error codes.
 6  #define     ZIO_OK      0       // No error.
 7  #define     ZIO_EHDL    ( -1 )  // Invalid handle.
 8  #define     ZIO_EMEM    ( -2 )  // Memory error.
 9  #define     ZIO_EIO     ( -3 )  // I/O error.
10  #define     ZIO_EARG    ( -4 )  // Invalid argument.
11  #define     ZIO_EFMT    ( -5 )  // Invalid format.
12  #define     ZIO_EINV    ( -6 )  // Unknown error.
13  
14  
15  #ifdef  __cplusplus
16  extern  "C" {
17  #endif
18  
19  
20  // Handle.
21  typedef     struct ZIO      *hZIO;
22  
23  // On memory.
24  typedef     struct ZMem
25  {
26      void    *buf;   // Buffer.
27      int     avail;  // Number of bytes available.
28      int     size;   // Buffer size.
29  }   ZMem, *hZMem;
30  
31  
32  // Compress.
33  int     ZIO_Compress( const char *src, const char *dst );
34  // Decompress.
35  int     ZIO_Decompress( const char *src, const char *dst );
36  
37  // Open (mode is [i][rw][0-9]).
38  //   i: Inverted mode (read and compress, decompress and write).
39  //  rw: Read from file or write to file.
40  // 0-9: Compression level (6: default, 0: faster, 9: smaller).
41  int     ZIO_Open( hZIO *h, const char *path, const char *mode );
42  // Close (flush output buffer).
43  int     ZIO_Close( hZIO h );
44  
45  // Read (return number of bytes read).
46  int     ZIO_Read( hZIO h, void *buf, int n );
47  // Write (return number of bytes written).
48  int     ZIO_Write( hZIO h, const void *buf, int n );
49  
50  // Load on memory (mode is passed to ZIO_Open()).
51  // This function reallocates memory to h->buf by realloc().
52  int     ZMem_Load( hZMem h, const char *path, const char *mode );
53  // Save to file (mode is passed to ZIO_Open()).
54  int     ZMem_Save( hZMem h, const char *path, const char *mode );
55  
56  
57  #ifdef  __cplusplus
58  }
59  #endif
60  
61  
62  #endif