exif: JavaScript parsing library

This page hosts a formal specification of exif using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

See the usage examples in the JavaScript notes.

Parse structure from an ArrayBuffer:

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

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

data.endianness // => get endianness

JavaScript source code to parse exif

Exif.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', './ExifBe', './ExifLe'], factory);
  } else if (typeof module === 'object' && module.exports) {
    module.exports = factory(require('kaitai-struct/KaitaiStream'), require('./ExifBe'), require('./ExifLe'));
  } else {
    root.Exif = factory(root.KaitaiStream, root.ExifBe, root.ExifLe);
  }
}(this, function (KaitaiStream, ExifBe, ExifLe) {
var Exif = (function() {
  function Exif(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  Exif.prototype._read = function() {
    this.endianness = this._io.readU2le();
    switch (this.endianness) {
    case 18761:
      this.body = new ExifLe(this._io, this, null);
      break;
    case 19789:
      this.body = new ExifBe(this._io, this, null);
      break;
    }
  }

  return Exif;
})();
return Exif;
}));