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

Application

Faster Than Light (FTL)

File extension

dat

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.

Usage

Runtime library

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

The JavaScript runtime library is available at npm:

npm install kaitai-struct

Code

See the usage examples in the JavaScript notes.

Parse structure from an ArrayBuffer:

var arrayBuffer = ...;
var data = new FtlDat(new KaitaiStream(arrayBuffer));

After that, one can get various attributes from the structure by accessing fields or properties like:

data.numFiles // => Number of files in the archive

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

FtlDat.js

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

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['kaitai-struct/KaitaiStream'], factory);
  } else if (typeof module === 'object' && module.exports) {
    module.exports = factory(require('kaitai-struct/KaitaiStream'));
  } else {
    root.FtlDat = factory(root.KaitaiStream);
  }
}(this, function (KaitaiStream) {
var FtlDat = (function() {
  function FtlDat(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  FtlDat.prototype._read = function() {
    this.numFiles = this._io.readU4le();
    this.files = new Array(this.numFiles);
    for (var i = 0; i < this.numFiles; i++) {
      this.files[i] = new File(this._io, this, this._root);
    }
  }

  var File = FtlDat.File = (function() {
    function File(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    File.prototype._read = function() {
      this.ofsMeta = this._io.readU4le();
    }
    Object.defineProperty(File.prototype, 'meta', {
      get: function() {
        if (this._m_meta !== undefined)
          return this._m_meta;
        if (this.ofsMeta != 0) {
          var _pos = this._io.pos;
          this._io.seek(this.ofsMeta);
          this._m_meta = new Meta(this._io, this, this._root);
          this._io.seek(_pos);
        }
        return this._m_meta;
      }
    });

    return File;
  })();

  var Meta = FtlDat.Meta = (function() {
    function Meta(_io, _parent, _root) {
      this._io = _io;
      this._parent = _parent;
      this._root = _root || this;

      this._read();
    }
    Meta.prototype._read = function() {
      this.lenFile = this._io.readU4le();
      this.lenFilename = this._io.readU4le();
      this.filename = KaitaiStream.bytesToStr(this._io.readBytes(this.lenFilename), "UTF-8");
      this.body = this._io.readBytes(this.lenFile);
    }

    return Meta;
  })();

  /**
   * Number of files in the archive
   */

  return FtlDat;
})();
return FtlDat;
}));