Xceed Binary Encoding Library Documentation
Examples / Streaming encoding from file to memory (VB example)
In This Topic
    Streaming encoding from file to memory (VB example)
    In This Topic

    This example encodes data in the Base64 format from a file to memory in 8K (8192 byte) chunks.

    Visual Basic Copy Code

    Const CHUNKSIZE = 8192

    Dim xEncode As New XceedBinaryEncoding

    Call xEncode.License( "your license key" ) 

    Dim lOffSet As Long
    Dim lFileSize As Long
    Dim vaBytesRead As Variant
    Dim vaEncoded As Variant 

    Set xEncode.EncodingFormat = New XceedBase64EncodingFormat 

    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. 

      vaEncoded = xEncode.ReadFile("c:\temp\source.txt", lOffSet, CHUNKSIZE, bfpEncode, _
                                   (lOffSet + CHUNKSIZE >= lFileSize), vaBytesRead)  

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

      lOffSet = lOffSet + vaBytesRead 
    Wend 

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