.dat file format of Faster Than Light (FTL): Python parsing library


Faster Than Light (FTL)

File extension


KS implementation details

License: CC0-1.0

This page hosts a formal specification of .dat file format of Faster Than Light (FTL) using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.


Runtime library

All parsing code for Python generated by Kaitai Struct depends on the Python runtime library. You have to install it before you can parse data.

The Python runtime library can be installed from PyPI:

python3 -m pip install kaitaistruct


Parse a local file and get structure in memory:

data = FtlDat.from_file("path/to/local/file.dat")

Or parse structure from a bytes:

from kaitaistruct import KaitaiStream, BytesIO

raw = b"\x00\x01\x02..."
data = FtlDat(KaitaiStream(BytesIO(raw)))

After that, one can get various attributes from the structure by invoking getter methods like:

data.num_files # => Number of files in the archive

Python source code to parse .dat file format of Faster Than Light (FTL)


# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import kaitaistruct
from kaitaistruct import KaitaiStruct, KaitaiStream, BytesIO

if getattr(kaitaistruct, 'API_VERSION', (0, 9)) < (0, 9):
    raise Exception("Incompatible Kaitai Struct Python API: 0.9 or later is required, but you have %s" % (kaitaistruct.__version__))

class FtlDat(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io
        self._parent = _parent
        self._root = _root if _root else self

    def _read(self):
        self.num_files = self._io.read_u4le()
        self.files = []
        for i in range(self.num_files):
            self.files.append(FtlDat.File(self._io, self, self._root))

    class File(KaitaiStruct):
        def __init__(self, _io, _parent=None, _root=None):
            self._io = _io
            self._parent = _parent
            self._root = _root if _root else self

        def _read(self):
            self.ofs_meta = self._io.read_u4le()

        def meta(self):
            if hasattr(self, '_m_meta'):
                return self._m_meta

            if self.ofs_meta != 0:
                _pos = self._io.pos()
                self._m_meta = FtlDat.Meta(self._io, self, self._root)

            return getattr(self, '_m_meta', None)

    class Meta(KaitaiStruct):
        def __init__(self, _io, _parent=None, _root=None):
            self._io = _io
            self._parent = _parent
            self._root = _root if _root else self

        def _read(self):
            self.len_file = self._io.read_u4le()
            self.len_filename = self._io.read_u4le()
            self.filename = (self._io.read_bytes(self.len_filename)).decode(u"UTF-8")
            self.body = self._io.read_bytes(self.len_file)