Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not copy typedarrays when converting to Buffer #31

Merged
merged 2 commits into from
Apr 10, 2014
Merged
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
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