RB-zlib

Fork me on GitHub

RB-zlib is a zlib binding for Realbasic and Xojo projects. It also supports reading and writing zip and tar archives.

Download Source(zip) | Documentation | Issue Tracker

License:zlib license Language: RealBasic
 

This project wraps zlib in an object-oriented, event-driven, Xojo-flavored syntax.

This example compresses and decompresses a string in memory:

  Dim compressed As String = zlib.Compress("Hello, world!")
  Dim decompressed As String = zlib.Uncompress(compressed)

This example gzips a file:

  Dim f As FolderItem = GetSaveFolderItem("") ' a file to be gzipped
  If f <> Nil Then
    Dim bs As BinaryStream = BinaryStream.Open(f)
    Dim g As FolderItem = f.Parent.Child(f.Name + ".gz")
    Dim gz As zlib.GZStream = zlib.GZStream.Create(g)
    gz.Level = 9 ' set the compression level as desired
    While Not bs.EOF
      gz.Write(bs.Read(1024))
    Wend
    bs.Close
    gz.Close
  End If

This example opens an existing gzip file and decompresses it into a `MemoryBlock`:

  Dim f As FolderItem = GetOpenFolderItem("") ' the gzip file to open
  If f <> Nil Then
    Dim gz As zlib.GZStream = zlib.GZStream.Open(f)
    Dim uncompressed As New MemoryBlock(0)
    Dim bs As BinaryStream = New BinaryStream(uncompressed)
    While Not gz.EOF
      bs.Write(gz.Read(1024))
    Wend
    bs.Close
    gz.Close
  End If

Refer to the documentation for additional examples and exposition.