PackToMem

From TotalcmdWiki
Jump to: navigation, search

PackToMem packs the next chunk of data passed to it and/or returns the compressed data to the calling program. It is implemented together with StartMemPack and DoneMemPack

 int __stdcall PackToMem (int hMemPack,char* BufIn,int InLen,int* Taken,char* BufOut,
                          int OutLen,int* Written,int SeekBy);

Function parameters

PackToMem should return MEMPACK_OK (=0) on success, MEMPACK_DONE (=1) when done, or one of the error values otherwise.

  • hMemPack is the handle returned by StartMemPack()
  • BufIn is a pointer to the data which needs to be packed
  • InLen contains the number of bytes pointed to by BufIn.
  • Taken has to receive the number of bytes taken from the buffer. If not the whole buffer is taken, the calling program will pass the remaining bytes to the plugin in a later call.
  • BufOut is a pointer to a buffer which can receive packed data
  • OutLen contains the size of the buffer pointed to by BufOut
  • Written has to receive the number of bytes placed in the buffer pointed to by BufOut
  • SeekBy may by set to the offset from the current output posisition by which the file pointer has to be moved BEFORE accepting the data in BufOut. This allows the plugin to modify a file header also AFTER packing, e.g. to write a CRC to the header.

Description

PackToMem is the most complex function of the packer plugin. It is called by Total Commander in a loop as long as there is data to be packed, and as there is data to retrieve. The plugin should do the following:

  1. As long as there is data sent through BufIn, take it and add it to your internal buffers (if there is enough space).
  2. As soon as there is enough data in the internal input buffers, start packing to the output buffers.
  3. As soon as there is enough data in the internal output buffers, start sending data to BufOut.
  4. When InLen is 0, there is no more data to be compressed, so finish sending data to BufOut until no more data is in the output buffer.
  5. When there is no more data available, return 1.
  6. There is no obligation to take any data through BufIn or send any through BufOut. Total Commander will call this function until it either returns 1, or an error.



Back to Packer plugins developer guide Back to Packer plugins developer guide overview Back to GetPackerCaps Back to DoneMemPack Back to StartMemPack