--- /dev/null
+var Atom = function(buffer, offset) {
+ this.size = 0;
+ this.type = '';
+ this.childAtoms = [];
+
+ return this.parse(buffer, offset)
+};
+
+Atom.prototype.parse = function(buffer, offset)
+{
+ // 'offset' is optional.
+ if (arguments.length < 2)
+ offset = 0;
+
+ // Atoms are 8 bytes minimum.
+ if (buffer.byteLength - offset < 8)
+ return null;
+
+ var view = new DataView(buffer, offset, 4);
+ this.size = view.getUint32(0);
+
+ var typeArrayView = new Uint8Array(buffer, offset + 4, 4);
+ this.type = String.fromCharCode.apply(null, typeArrayView);
+
+ return this;
+};
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+<head>
+ <title>AtomTester</title>
+ <script src=Atom.js></script>
+ <script>
+ var atoms = [];
+ function onFileSelect(e) {
+ var file = e.target.files[0];
+ var reader = new FileReader();
+ reader.onload = (function(file) {
+ return function(e) {
+ var offset = 0;
+ while (offset < e.target.result.byteLength) {
+ var atom = new Atom(e.target.result, offset);
+ if (!atom)
+ break;
+ atoms.push(atom);
+ offset += atom.size;
+ }
+ };
+ })(file);
+ reader.readAsArrayBuffer(file);
+ }
+
+ function setup() {
+ document.getElementById('file').addEventListener('change', onFileSelect, false);
+ }
+ </script>
+</head>
+<body id="atomtester" onload="setup()">
+ <input type="file" id="file" name="file" />
+</body>
\ No newline at end of file