Created
October 10, 2013 05:36
-
-
Save brycebaril/6913533 to your computer and use it in GitHub Desktop.
Run setup.js to create the file the other two use
This file contains 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
var probuf = require("leveljs-coding/protobuf") | |
var fs = require("fs") | |
var concat = require("concat-stream") | |
var input = fs.createReadStream("buffs") | |
input.pipe(concat(function (buffer) { | |
var offset = 0 | |
var blen = buffer.length | |
while (offset < blen) { | |
var result = probuf.readVarInt64(buffer, offset) | |
offset += result[1] | |
} | |
})) |
This file contains 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
var encode = require("varint/encode") | |
var buffs = [] | |
for (var i = 0; i < 3000000; i++) { | |
buffs.push(Buffer(encode(i))); | |
} | |
module.exports = buffs | |
var fs = require("fs") | |
var ws = fs.createWriteStream("buffs") | |
ws.write(Buffer.concat(buffs)) |
This file contains 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
var Decoder = require("varint/decode") | |
var fs = require("fs") | |
var concat = require("concat-stream") | |
var input = fs.createReadStream("buffs") | |
input.pipe(concat(function (buffer) { | |
var d = new Decoder() | |
var inLength = true | |
var length = false | |
d.ondata = function (num) { | |
length = num | |
inLength = false | |
} | |
var offset = 0 | |
var blen = buffer.length | |
while (offset < blen) { | |
if (inLength) { | |
var bit = buffer.readUInt8(offset) | |
d.write(bit) | |
offset++ | |
} | |
else { | |
inLength = true | |
} | |
} | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment