Skip to content

BZip2.Compress

Andrew Lambert edited this page Nov 27, 2022 · 4 revisions

BZip2.Compress

Method Signatures

 Protected Function Compress(Source As FolderItem, Destination As FolderItem, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION, Overwrite As Boolean = False) As Boolean
 Protected Function Compress(Source As FolderItem, Destination As Writeable, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION) As Boolean
 Protected Function Compress(Source As MemoryBlock, Destination As FolderItem, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION, Overwrite As Boolean = False) As Boolean
 Protected Function Compress(Source As MemoryBlock, Destination As Writeable, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION) As Boolean
 Protected Function Compress(Source As Readable, Destination As FolderItem, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION, Overwrite As Boolean = False) As Boolean
 Protected Function Compress(Source As Readable, Destination As Writeable, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION) As Boolean
 Protected Function Compress(Source As FolderItem, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION) As MemoryBlock
 Protected Function Compress(Source As MemoryBlock, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION) As MemoryBlock
 Protected Function Compress(Source As Readable, CompressionLevel As Integer = BZip2.Z_DEFAULT_COMPRESSION) As MemoryBlock

Parameters

Name Type Comment
Source FolderItem, Readable, or MemoryBlock The data to compress
Destination FolderItem or Writeable The file or stream to which compressed data should be written. Methods which return a MemoryBlock do not have this parameter
CompressionLevel Integer Optional. If specified, the compression level to use (0=none, 1=fast, 9=best)
Overwrite Boolean Optional. If True, the Destination FolderItem will be overwritten if it exists. Only those methods with FolderItem destinations have this parameter

Return value

Returns True if there were no errors writing to a Writeable or FolderItem; or, a MemoryBlock containing the compressed data.

Remarks

Compresses data from the Source argument into the Destination argument; methods without a Destination parameter return the compressed data instead.

Examples

Compress a string into a string:

  Dim data As String = "hello, world!"
  Dim comp As String = BZip2.Compress(data)

Compress a string into a file:

  Dim data As String = "hello, world!"
  Dim comp As FolderItem = SpecialFolder.Desktop.Child("example.bin")
  If Not BZip2.Compress(data, comp) Then
    MsgBox("BZip2 error!")
  End If

Compress a file into a string:

  Dim data As FolderItem = SpecialFolder.Desktop.Child("example.bin")
  Dim comp As String = BZip2.Compress(data)

See also

Clone this wiki locally