Skip to content
Dion Mendel edited this page Jun 25, 2023 · 8 revisions

Navigation


Quick Start

Stop writing code like this.

def read_fancy_format(io)
  comment, len, rest = io.read.unpack("Z*Ca*")
  data = rest.unpack("N#{len}")
  {:comment => comment, :len => len, :data => *data}
end

Instead, write code like this.

class MyFancyFormat < BinData::Record
  stringz :comment
  uint8   :len
  array   :data, type: :int32be, initial_length: :len
end

Creating a Record

Start by subclassing BinData::Record.

Add fields for each attribute of the file format.

Most fields will be primitive types (numbers and strings).

You will also use compound types such as arrays, nested records or choices.

Once you're created your new subclass, there are common operations to perform.

Clone this wiki locally