Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var eos = require('end-of-stream')
var ids = require('numeric-id-map')
var lpstream = require('length-prefixed-stream')
var messages = require('./messages')
var bufferAlloc = require('buffer-alloc')

var ENCODERS = [
messages.Get,
Expand Down Expand Up @@ -206,7 +207,7 @@ Multilevel.prototype._batch = function (batch, opts, cb) {
Multilevel.prototype._write = function (req) {
if (this._requests.length + this._iterators.length === 1) ref(this._ref)
var enc = ENCODERS[req.tag]
var buf = new Buffer(enc.encodingLength(req) + 1)
var buf = bufferAlloc(enc.encodingLength(req) + 1)
buf[0] = req.tag
enc.encode(req, buf, 1)
this._encode.write(buf)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"dependencies": {
"abstract-leveldown": "^2.4.1",
"buffer-alloc": "^1.1.0",
"duplexify": "^3.4.2",
"end-of-stream": "^1.1.0",
"length-prefixed-stream": "^1.4.0",
Expand Down
5 changes: 3 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var lpstream = require('length-prefixed-stream')
var eos = require('end-of-stream')
var duplexify = require('duplexify')
var messages = require('./messages')
var bufferAlloc = require('buffer-alloc')

var DECODERS = [
messages.Get,
Expand Down Expand Up @@ -72,7 +73,7 @@ module.exports = function (db, opts) {

function callback (id, err, value) {
var msg = {id: id, error: err && err.message, value: value}
var buf = new Buffer(messages.Callback.encodingLength(msg) + 1)
var buf = bufferAlloc(messages.Callback.encodingLength(msg) + 1)
buf[0] = 0
messages.Callback.encode(msg, buf, 1)
encode.write(buf)
Expand Down Expand Up @@ -163,7 +164,7 @@ function Iterator (down, req, encode) {
self._data.key = key
self._data.value = value
self.batch--
var buf = new Buffer(messages.IteratorData.encodingLength(self._data) + 1)
var buf = bufferAlloc(messages.IteratorData.encodingLength(self._data) + 1)
buf[0] = 1
messages.IteratorData.encode(self._data, buf, 1)
encode.write(buf)
Expand Down