Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.