Skip to content

Commit

Permalink
Merge pull request #31 from mafintosh/typedarray-to-buffer
Browse files Browse the repository at this point in the history
Do not copy typedarrays when converting to Buffer
  • Loading branch information
Max Ogden committed Apr 10, 2014
2 parents a952571 + d18297a commit 714b756
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 714b756

Please sign in to comment.