Skip to content

CompressBank

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

CompressBank BlitzLLVM

CompressBank:Int32 bank:Int32, offset:Int32=0, count:Int32=-1, level:Int32=6, format:Int32=0
Parameter Mode Type Default Description
bank In Int32 required The bank with the data.
offset In Int32 0 Where in the bank the data starts.
count In Int32 -1 How many bytes to compress, or -1 for everything from the offset to the end of the bank.
level In Int32 6 How hard zlib tries, from 0 (store only) to 9 (smallest). Ignored by LZ4.
format In Int32 0 0 for zlib, 1 for LZ4.

Returns: A new bank with the size and the compressed data.

Description

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

Packs bytes of a bank into a new, smaller bank, which DecompressBank turns back into the same bytes. This is a BlitzLLVM extension: the originals have no compression. Use it to make maps, saves and network messages smaller before writing or sending them.

  • The new bank starts with the original size in 4 bytes (read it with PeekInt(packed, 0)), followed by the compressed data. DecompressBank needs that size, so keep the bank as it is.
  • Format 0 is zlib, compressed with zlib-ng. It makes data the smallest, and it checks the data when unpacking. After the 4 bytes of the size it is a standard zlib stream (RFC 1950), so other programs and languages can read it with any zlib.
  • Format 1 is LZ4. It packs and unpacks several times as fast as zlib but makes data a bit bigger, which suits data sent many times a second, like the positions of everything in a multiplayer game. After the 4 bytes it is a standard LZ4 block (not an LZ4 frame). It has no checksum, so send it over a connection that checks the data itself (TCP does), or add a checksum of your own.
  • The level only matters for zlib: 0 stores the data without compressing it, 1 is the fastest and 9 the smallest, and 6 is a good balance. LZ4 has one speed and ignores the level.
  • Data that does not compress, such as data that is already compressed, gets a few bytes bigger.
  • At most 256 MiB can be compressed, as DecompressBank refuses anything bigger.
  • Free the new bank with FreeBank when it is not needed any more.

Examples

original = CreateBank(10000)
For i = 0 To 9999
	PokeByte original, i, i Mod 10
Next
packed = CompressBank(original)
Print "Packed: " + BankSize(packed) + " bytes"
unpacked = DecompressBank(packed)
Print "Unpacked: " + BankSize(unpacked) + " bytes, byte 1234 is " + PeekByte(unpacked, 1234)
FreeBank unpacked
FreeBank packed
FreeBank original
Packed: 93 bytes
Unpacked: 10000 bytes, byte 1234 is 4

Related Commands

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

Home · Command Index


Getting started

Language

Tools


Language Features
BlitzBasic
Blitz3D
BlitzPlus
Differences

More

Clone this wiki locally