Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | var Parser = require("../lib/binary_parser").Parser; var SOI = Parser.start(); var EOI = Parser.start(); var APP0 = Parser.start() .endianess("big") .uint16("length") .string("id", { encoding: "ascii", zeroTerminated: true, validate: "JFIF" }) .uint16("version") .uint8("unit") .uint16("xDensity") .uint16("yDensity") .uint8("thumbWidth") .uint8("thumbHeight") .array("thumbData", { type: "uint8", length: function() { return this.Xt * this.Yt * 3; } }); var COM = Parser.start() .endianess("big") .uint16("length") .string("comment", { encoding: "ascii", length: function() { return this.length - 2; } }); var SOS = Parser.start() .endianess("big") .uint16("length") .uint8("componentCount") .array("components", { type: Parser.start() .uint8("id") .uint8("dht"), length: "componentCount" }) .uint8("spectrumStart") .uint8("spectrumEnd") .uint8("spectrumSelect"); var DQT = Parser.start() .endianess("big") .uint16("length") .array("tables", { type: Parser.start() .uint8("precisionAndTableId") .array("table", { type: "uint8", length: 64 }), length: function() { return (this.length - 2) / 65; } }); var SOF0 = Parser.start() .endianess("big") .uint16("length") .uint8("precision") .uint16("width") .uint16("height") .uint8("componentCount") .array("components", { type: Parser.start() .uint8("id") .uint8("samplingFactor") .uint8("quantizationTableId"), length: "componentCount" }); var Ignore = Parser.start() .endianess("big") .uint16("length") .skip(function() { return this.length - 2; }); var Segment = Parser.start() .endianess("big") .uint16("marker") .choice("segment", { tag: "marker", choices: { 0xffd8: SOI, 0xffd9: EOI, 0xffe0: APP0, 0xffda: SOS, 0xffdb: DQT, 0xffc0: SOF0 }, defaultChoice: Ignore }); var JPEG = Parser.start().array("segments", { type: Segment, readUntil: "eof" }); require("fs").readFile("test.jpg", function(err, data) { console.log(require("util").inspect(JPEG.parse(data), { depth: null })); }); |