/* zip.h : packing/unpacking using Deflate+Huffman Algorithm */ //------------------------------------------------------------------------- // 1) high-level routines for memory block //------------------------------------------------------------------------- // compressed block can become at most 1 byte larger than source block void compress_block ( byte[] block_in, out byte[] block_out, out int block_out_size); // block_out_size becomes zero in case of bad compression format void decompress_block ( byte[] block_in, out byte[] block_out, out int block_out_size); // returns null if decompression failed byte[]^ decompress_and_allocate_block (byte[] block_in); //------------------------------------------------------------------------- // 2) high-level routines for files //------------------------------------------------------------------------- // returns 0 if OK, -1 if i/o or format error. int compress_file (string source, string target); int decompress_file (string source, string target); //------------------------------------------------------------------------- // 3) low-level routines with callback functions //------------------------------------------------------------------------- const int UNPACK_MAX_READ_AHEAD = 32768; //-------------------------------------------------------------------------- struct READ_AHEAD { uint size; /* nb bytes in 'buffer' */ byte buffer[UNPACK_MAX_READ_AHEAD]; } //-------------------------------------------------------------------------- /* 'user_info' can be used to pass data to the user's i/o functions */ generic package PACK //-------------------------------------------------------------------- /* user-provided read function. */ /* must return the number of bytes transferred, */ /* zero in case of end-of-data, */ /* or a negative value in case of error. */ typedef int IO_READ (ref USER_INFO user_info, out byte[] buffer); //-------------------------------------------------------------------- /* user-provided write function. */ /* must return the number of bytes transferred, */ /* or a negative value in case of error. */ typedef int IO_WRITE (ref USER_INFO user_info, byte[] buffer); //-------------------------------------------------------------------- int pack (ref USER_INFO user_info, IO_READ user_read, IO_WRITE user_write); //-------------------------------------------------------------------- end PACK; //-------------------------------------------------------------------- /* pack error codes: */ const int PK_READ_ERROR = (-1); /* error in user_read */ const int PK_WRITE_ERROR = (-2); /* error in user_write */ const int PK_STACK_ERROR = (-3); /* out of stack space */ const int PK_INTERN_1 = (-4); /* intern error (should never occur) */ //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- /* 'user_info' can be used to pass data to the user's i/o functions */ generic package UNPACK //-------------------------------------------------------------------- /* user-provided read function. */ /* must return the number of bytes transferred, */ /* zero in case of end-of-data, */ /* or a negative value in case of error. */ typedef int IO_READ (ref USER_INFO user_info, out byte[] buffer); //-------------------------------------------------------------------- /* user-provided write function. */ /* must return the number of bytes transferred, */ /* or a negative value in case of error. */ typedef int IO_WRITE (ref USER_INFO user_info, byte[] buffer); //-------------------------------------------------------------------- /* note: unpack() reads data in large blocks and will probably read */ /* past the compression part. The data read but not used by */ /* unpack will be returned in the structure 'extra'. */ int unpack (ref USER_INFO user_info, IO_READ user_read, IO_WRITE user_write, out READ_AHEAD extra); //-------------------------------------------------------------------- end UNPACK; //-------------------------------------------------------------------- /* unpack error codes: */ const int UNPK_READ_ERROR = (-1); /* error in user_read */ const int UNPK_WRITE_ERROR = (-2); /* error in user_write */ const int UNPK_STACK_ERROR = (-3); /* out of stack space */ const int UNPK_BAD_BTYPE = (-4); /* bad field BTYPE */ const int UNPK_BAD_NLEN = (-5); /* bad field NLEN */ const int UNPK_HUFF_OVERFLOW = (-6); /* bad format */ const int UNPK_HUFF_BAD_STRUCT = (-7); /* bad format */ const int UNPK_HUFF_BAD_CODE = (-8); /* bad format */ const int UNPK_NO_PREV_CODE = (-9); /* bad format */ const int UNPK_TOO_MANY = (-10); /* bad format */ const int UNPK_BAD_CODE = (-11); /* bad format */ //--------------------------------------------------------------------