Another example. I've included 2 easy functions I found through the forums, and added an extra feature to automatically deal with the size of the bank destination, so you can just use compressbank/uncompressbank functions without needing to know the destination size when decompressing it:
Local Bank:TBank = CreateBank()
Local BStream:TStream = CreateBankStream(Bank)
BStream.WriteString("a bunch of data!")
Bank = compressBank(Bank) 'And your bank is now compressed
'This next line is for testing purposes
'to relink the stream to the compressed bank,
'so we can print out the compressed data
BStream = CreateBankStream(Bank)
Print "~n~nCompressed: " + BStream.ReadString(BStream.size())
'Now lets uncompress that data, and print it out
Bank = uncompressBank(Bank)
BStream = CreateBankStream(Bank)
Print "~n~nUncompressed: " + BStream.ReadString(BStream.size())
Function compressBank:TBank(sourceBank:TBank, level:Int = 9)
Local CurrentSize:Int = SourceBank.Size()
Local destBankSize:Int = Ceil(sourceBank.Size() * 1.001) + 2 + 4
Local destBank:TBank = CreateBank(destBankSize)
compress2(destBank.Buf(), destBankSize, sourceBank.Buf(), sourceBank.Size(), level)
'resize bank to it's compressed size
destBank.Resize(destBankSize+4)
'The size of the bank is included at the end - so you don't need to know the destination size later
destBank.PokeInt(destBankSize,CurrentSize)
Return destBank
End Function
Function uncompressBank:TBank(sourceBank:TBank)
Local destBankSize:Int = sourceBank.PeekInt(Sourcebank.size()-4)
Local destBank:TBank = CreateBank(destBankSize)
uncompress(destBank.Buf(), destBankSize, sourceBank.Buf(), sourceBank.Size())
Return destBank
End Function