From 9b8f8a6a44dcb9ca3710dd7cb5c30487e342b074 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Tue, 8 Apr 2014 11:11:10 +0200 Subject: [PATCH 1/2] added typedarray-to-buffer --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 45d5e9a..ed23495 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,8 @@ "xtend": "~2.1.2", "tape": "~2.10.2", "browserify": "~3.32.0", - "abstract-leveldown": "~0.12.0" + "abstract-leveldown": "~0.12.0", + "typedarray-to-buffer": "~1.0.0" }, "testling": { "files": "test/test.js", From d18297a9d5fba18721f341eb03f30038dc5d2562 Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Tue, 8 Apr 2014 11:14:16 +0200 Subject: [PATCH 2/2] use toBuffer instead of copying typedarrays --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 53c0637..806b33a 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ var util = require('util') var Iterator = require('./iterator') var isBuffer = require('isbuffer') var xtend = require('xtend') +var toBuffer = require('typedarray-to-buffer') function Level(location) { if (!(this instanceof Level)) return new Level(location) @@ -47,7 +48,7 @@ Level.prototype._get = function (key, options, callback) { if (options.asBuffer === false) asBuffer = false if (options.raw) asBuffer = false if (asBuffer) { - if (value instanceof Uint8Array) value = new Buffer(value) + if (value instanceof Uint8Array) value = toBuffer(value) else value = new Buffer(String(value)) } return callback(null, value, key) @@ -60,7 +61,7 @@ Level.prototype._del = function(id, options, callback) { Level.prototype._put = function (key, value, options, callback) { if (value instanceof ArrayBuffer) { - value = new Buffer(new Uint8Array(value)) + value = toBuffer(new Uint8Array(value)) } var obj = this.convertEncoding(key, value, options) if (Buffer.isBuffer(obj.value)) {