Created
November 8, 2013 23:18
-
-
Save phaus/7379217 to your computer and use it in GitHub Desktop.
Reading Binary Files with node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./readMul.sh | |
size: 3072, maxID: 256 | |
[ 813, 9, 15 ] | |
Alchemy 0 | |
[ 1408, 9, 13 ] | |
Anatomy 0 | |
[ 1395, 13, 13 ] | |
Animal Lore 0 | |
[ 1372, 21, 13 ] | |
Item Identification 0 | |
[ 4956, 11, 13 ] | |
Arms Lore 0 | |
[ 1346, 10, 13 ] | |
Parrying 0 | |
[ 1337, 9, 13 ] | |
Begging 0 | |
[ 1322, 13, 13 ] | |
Blacksmithy 0 | |
[ 1301, 20, 13 ] | |
Bowcraft/Fletching 0 | |
[ 1288, 13, 13 ] | |
Peacemaking 0 | |
[ 1279, 9, 15 ] | |
Camping 0 | |
[ 589, 11, 13 ] | |
Carpentry 0 | |
[ 1266, 13, 13 ] | |
Cartography 0 | |
[ 1257, 9, 13 ] | |
Cooking 0 | |
[ 4938, 18, 13 ] | |
Detecting Hidden 0 | |
[ 4926, 12, 13 ] | |
Enticement 0 | |
[ 4901, 25, 13 ] | |
Evaluating Intelligence 0 | |
[ 1200, 9, 13 ] | |
Healing 0 | |
[ 1191, 9, 13 ] | |
Fishing 0 | |
[ 1170, 21, 13 ] | |
Forensic Evaluation 0 | |
[ 1161, 9, 13 ] | |
Herding 0 | |
[ 1153, 8, 13 ] | |
Hiding 0 | |
[ 1138, 13, 13 ] | |
Provocation 0 | |
[ 1123, 13, 13 ] | |
Inscription 0 | |
[ 1110, 13, 13 ] | |
Lockpicking 0 | |
[ 4893, 8, 14 ] | |
Magery 0 | |
[ 1072, 9, 13 ] | |
Tactics 0 | |
[ 4865, 10, 13 ] | |
Snooping 0 | |
[ 1049, 14, 13 ] | |
Musicianship 0 | |
[ 1038, 11, 13 ] | |
Poisoning 0 | |
[ 1022, 9, 13 ] | |
Archery 0 | |
[ 1008, 14, 13 ] | |
Spirit Speak 0 | |
[ 4875, 18, 13 ] | |
Resisting Spells 0 | |
[ 830, 10, 14 ] | |
Stealing 0 | |
[ 997, 11, 13 ] | |
Tailoring 0 | |
[ 4850, 15, 13 ] | |
Animal Taming 0 | |
[ 4828, 22, 13 ] | |
Taste Identification 0 | |
[ 952, 11, 13 ] | |
Tinkering 0 | |
[ 942, 10, 13 ] | |
Tracking 0 | |
[ 928, 12, 13 ] | |
Veterinary 0 | |
[ 909, 15, 13 ] | |
Swordsmanship 0 | |
[ 892, 15, 13 ] | |
Mace Fighting 0 | |
[ 871, 9, 13 ] | |
Fencing 0 | |
[ 850, 11, 13 ] | |
Wrestling 0 | |
[ 4805, 8, 2 ] | |
Mining 0 | |
[ 4967, 12, 1 ] | |
Meditation 0 | |
[ 4813, 15, 2 ] | |
Lumberjacking 0 | |
[ 4992, 9, 1 ] | |
Stealth 0 | |
[ 4979, 13, 1 ] | |
Remove Trap 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/nodejs | |
var fs = require("fs"); | |
var jParser = require('jParser'); | |
var mulIndex = "skills.idx"; | |
var mulData = "skills.mul"; | |
var stats = fs.statSync(mulIndex); | |
var fileSizeInBytes = stats["size"]; | |
var maxIndex = fileSizeInBytes/12; | |
console.log("size: "+fileSizeInBytes+", maxID: "+maxIndex); | |
var mulParser = function(entry) { | |
var pos = entry[0]; | |
var length = entry[1]; | |
fs.readFile(mulData, function(err, data){ | |
var parser = new jParser(data, { | |
isAction: ['uint8', 1], | |
name: ['string', length-1] | |
}); | |
parser.seek(pos); | |
console.log(entry); | |
console.log(parser.parse('name')+" "+parser.parse('isAction')); | |
}); | |
} | |
var idxParser = function(err, data) { | |
var parser = new jParser(data, { | |
// lookup, length, extra | |
entry: ['array', 'int32', 3] | |
}); | |
for(var i=0; i < maxIndex; i++) { | |
parser.seek(i*12); | |
entry = parser.parse('entry'); | |
if(entry[0] >= 0){ | |
mulParser(entry); | |
} else { | |
break; | |
} | |
} | |
} | |
fs.readFile(mulIndex, idxParser); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment