Xceed Streaming Compression Library Documentation
Examples / Streaming compression from file to memory (VB example)
In This Topic
    Streaming compression from file to memory (VB example)
    In This Topic
    Visual Basic Copy Code

    ' This example compresses data in the GZip format
    ' from a file to memory in 8K (8192 byte) chunks. 

    Const CHUNKSIZE = 8192

    Dim xCompress As New XceedStreamingCompression

    Call xCompress.License( "your license key" ) 

    Dim lOffSet As Long
    Dim lFileSize As Long
    Dim vaBytesRead As Variant
    Dim vaCompressed As Variant 

    Set xCompress.CompressionFormat = New XceedGZipCompressionFormat 

    lOffSet = 0 ' We must track the current offset 

    On Error Resume Next 

    lFileSize = FileLen("c:\temp\source.txt")

    While lOffSet < lFileSize
      'bEndOfData will be true if the current offset + CHUNKSIZE exceeds the 
      'end of the file. 
      vaCompressed = xCompress.ReadFile("c:\temp\source.txt", lOffSet, CHUNKSIZE, cfpCompress, _
                                        (lOffSet + CHUNKSIZE >= lFileSize), vaBytesRead)  

      If Not IsEmpty(vaCompressed) Then 
        ' You now have a portion of compressed data you can use. 
        ' For example, transfer it, process it, etc. 
      End If  

      lOffSet = lOffSet + vaBytesRead 
    Wend 

    If Err.Number = 0 Then
      MsgBox "Finished compressing file to memory." 
    Else
      MsgBox Err.Number & " " & Err.Description 
    End If