PackerCallback()

Syntax

Result = PackerCallback(@Callback())
Description
Set a callback to monitor or abort the compression for CompressMemory(), AddPackFile() and AddPackMemory(). The callback will be called at regular intervalls during the compression process.

Parameters

@Callback() The address of a callback function to call. It must have the following form:
  Procedure Callback(Current.q, Total.q)
    ;
    ; Returns #True as result to continue to compress, or #False to abort.
    ;
    ProcedureReturn Result
  EndProcedure

Return value

None.

Example

  UseZipPacker()
   
  ; The callback will be called at regular intervall, to allow to display
  ; some progress or abort the compression. It must match the following declaration.
  ;
  Procedure Callback(Current.q, Total.q)
    Debug "Progress: " + Current + " bytes / "+ Total + " bytes"
    
    ProcedureReturn #True ; Returns #True to continue to compress, or #False to abort
  EndProcedure
    
  ; Install the callback for all the future packer compression  
  PackerCallback(@Callback())
  
  ; Allocate 50 GB of memory to compress it
  *Buffer = AllocateMemory(50*1024*1024, #PB_Memory_NoClear)
  
  ; The output buffer a bit bigger than source, just in case
  *Output = AllocateMemory(51*1024*1024, #PB_Memory_NoClear)

  CompressedSize = CompressMemory(*Buffer, MemorySize(*Buffer), *Output, MemorySize(*Output))

  Debug "Compressed length: " + CompressedSize + " bytes"

See Also

CompressMemory(), AddPackFile(), AddPackMemory()

Supported OS

All

<- PackEntryType() - Packer Index - UncompressMemory() ->