DataCompress Event

Fires to compress a block of data using a custom compression algorithm.

Syntax

public event OnDataCompressHandler OnDataCompress;

public delegate void OnDataCompressHandler(object sender, CbvaultDataCompressEventArgs e);

public class CbvaultDataCompressEventArgs : EventArgs {
  public IntPtr InData { get; }
  public int InSize { get; }
  public IntPtr OutData { get; }
  public int OutSize { get; set; }
  public int CompressionLevel { get; }
  public int ResultCode { get; set; }
}
Public Event OnDataCompress As OnDataCompressHandler

Public Delegate Sub OnDataCompressHandler(sender As Object, e As CbvaultDataCompressEventArgs)

Public Class CbvaultDataCompressEventArgs Inherits EventArgs
  Public ReadOnly Property InData As IntPtr
  Public ReadOnly Property InSize As Integer
  Public ReadOnly Property OutData As IntPtr
  Public Property OutSize As Integer
  Public ReadOnly Property CompressionLevel As Integer
  Public Property ResultCode As Integer
End Class

Remarks

This event fires when the component needs to compress a block of data using an application-defined compression algorithm. Please refer to the Compression topic for more information.

This event only needs to be handled by applications that use the CBFSSTORAGE_CM_CUSTOM compression mode. To handle this event properly, applications must compress all InSize bytes of data in the InData buffer, write the compressed data to the OutData buffer, and set OutSize to reflect the total number of bytes written to OutData.

Note that OutSize is initially set to the capacity of the OutData buffer. If the OutData buffer is not large enough to accommodate all of the data after compression (which, while uncommon, may occur with some compression algorithms), do not write any data to OutData. Instead, set ResultCode to CBFSSTORAGE_ERR_BUFFER_TOO_SMALL to inform the component that the current block of data should remain uncompressed.

Please refer to the Buffer Parameters topic for more information on how to work with memory buffer event parameters.

The CompressionLevel specifies the requested compression level. Possible values are 0 through 9; where 0 means "use the default compression level". Applications may ignore this value if it is not needed by their compression algorithm.

The ResultCode parameter will always be 0 when the event is fired. If the event cannot be handled in a "successful" manner for some reason (e.g., a resource isn't available, security checks failed, etc.), set it to a non-zero value to report an appropriate error. Please refer to the Error Reporting and Handling topic for more information.

Note: An application should not attempt to call component's methods from handlers of this event. Doing this is guaranteed to cause a deadlock.

Note: when a storage is opened concurrently in read-only mode by several applications using CBDrive or CBMemDrive component, the event will fire only in the first application. To prevent such a situation, always open a vault in read-write mode.

Copyright (c) 2021 Callback Technologies, Inc. - All rights reserved.
CBFS Vault 2020 .NET Edition - Version 20.0 [Build 7982]