.bmp file format of Heroes of Might and Magic: JavaScript parsing library

Application

Heroes of Might and Magic

File extension

bmp

KS implementation details

License: CC0-1.0

This page hosts a formal specification of .bmp file format of Heroes of Might and Magic using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Runtime library

All JavaScript code generated by Kaitai Struct depends on the Kaitai Struct runtime library for JavaScript. You must add this dependency to your project before you can parse or serialize any 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 HeroesOfMightAndMagicBmp(new KaitaiStream(arrayBuffer));

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

data.magic // => get magic

JavaScript source code to parse .bmp file format of Heroes of Might and Magic

HeroesOfMightAndMagicBmp.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(['exports', 'kaitai-struct/KaitaiStream'], factory);
  } else if (typeof exports === 'object' && exports !== null && typeof exports.nodeType !== 'number') {
    factory(exports, require('kaitai-struct/KaitaiStream'));
  } else {
    factory(root.HeroesOfMightAndMagicBmp || (root.HeroesOfMightAndMagicBmp = {}), root.KaitaiStream);
  }
})(typeof self !== 'undefined' ? self : this, function (HeroesOfMightAndMagicBmp_, KaitaiStream) {
var HeroesOfMightAndMagicBmp = (function() {
  function HeroesOfMightAndMagicBmp(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  HeroesOfMightAndMagicBmp.prototype._read = function() {
    this.magic = this._io.readU2le();
    this.width = this._io.readU2le();
    this.height = this._io.readU2le();
    this.data = this._io.readBytes(this.width * this.height);
  }

  return HeroesOfMightAndMagicBmp;
})();
HeroesOfMightAndMagicBmp_.HeroesOfMightAndMagicBmp = HeroesOfMightAndMagicBmp;
});