]> id.pley.net Git - movie_parser.git/commitdiff
First version.
authorJer Noble <jer.noble@apple.com>
Thu, 6 Dec 2012 19:37:23 +0000 (11:37 -0800)
committerJer Noble <jer.noble@apple.com>
Thu, 6 Dec 2012 19:37:23 +0000 (11:37 -0800)
Atom.js [new file with mode: 0644]
AtomTester.html [new file with mode: 0644]

diff --git a/Atom.js b/Atom.js
new file mode 100644 (file)
index 0000000..50ba17f
--- /dev/null
+++ b/Atom.js
@@ -0,0 +1,26 @@
+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
diff --git a/AtomTester.html b/AtomTester.html
new file mode 100644 (file)
index 0000000..789e246
--- /dev/null
@@ -0,0 +1,32 @@
+<!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