Skip to content

Instantly share code, notes, and snippets.

@brycebaril
Created October 10, 2013 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brycebaril/6913533 to your computer and use it in GitHub Desktop.
Save brycebaril/6913533 to your computer and use it in GitHub Desktop.
Run setup.js to create the file the other two use
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]
}
}))
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))
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