Skip to content

DecompressBank

Narta Xaymar Dirks edited this page Dec 2, 2026 · 1 revision

DecompressBank BlitzLLVM

DecompressBank:Int32 bank:Int32, offset:Int32=0, count:Int32=-1, format:Int32=0
Parameter Mode Type Default Description
bank In Int32 required The bank with the compressed data.
offset In Int32 0 Where in the bank the compressed data starts (its 4 bytes of size).
count In Int32 -1 How many bytes the compressed data has, or -1 for everything from the offset to the end of the bank.
format In Int32 0 0 for zlib, 1 for LZ4.

Returns: A new bank with the original bytes, or 0 if the data is broken.

Description

BlitzLLVM This command does not exist in the original Blitz products. BlitzLLVM adds it.

Unpacks a bank made by CompressBank into a new bank with the original bytes. This is a BlitzLLVM extension: the originals have no compression.

  • The format has to be the one the data was compressed with: 0 for zlib, 1 for LZ4.
  • Data that is broken gives 0 instead of a bank: data that was cut off or changed, data in the other format, or data that is not compressed at all. Always check for 0 before using the result. zlib also finds single changed bytes with its checksum, LZ4 does not have one.
  • It is safe to unpack data that comes from other computers, even from a player who sends broken data on purpose. The size at the start of the data is checked before anything is allocated: it has to be at most 256 MiB, and possible for the amount of compressed data (zlib can make at most 1032 bytes of each byte, LZ4 at most 255). The data never writes outside of the new bank. To allow less than 256 MiB, check PeekInt(packed, offset) yourself first.
  • The data has to fill exactly the bytes given by offset and count. A message that has more after the compressed data needs the count of the compressed part.
  • Free the new bank with FreeBank when it is not needed any more.

Examples

message = CreateBank(200)
For i = 0 To 199
	PokeByte message, i, 65 + (i Mod 3)
Next
packed = CompressBank(message, 0, -1, 6, 1)
unpacked = DecompressBank(packed, 0, -1, 1)
Print "LZ4: " + BankSize(packed) + " bytes, unpacked to " + BankSize(unpacked)
FreeBank unpacked
PokeInt packed, 0, 1000000 ; A size that this little data can not have.
Print "Broken: " + DecompressBank(packed, 0, -1, 1)
FreeBank packed
FreeBank message
LZ4: 17 bytes, unpacked to 200
Broken: 0

Related Commands

BankSize BlitzBasic, CompressBank BlitzLLVM, CopyBank BlitzBasic, CreateBank BlitzBasic, FreeBank BlitzBasic, ResizeBank BlitzBasic

Home · Command Index


Getting started

Language

Tools


Language Features
BlitzBasic
Blitz3D
BlitzPlus
Differences

More

Clone this wiki locally