localstorage-down
Advanced tools
Comparing version 0.6.0 to 0.6.1
10
index.js
@@ -179,3 +179,3 @@ 'use strict'; | ||
if (!isBuffer(key)) { | ||
if (!Buffer.isBuffer(key)) { | ||
key = String(key); | ||
@@ -213,3 +213,3 @@ } | ||
} | ||
if (!isBuffer(key)) { | ||
if (!Buffer.isBuffer(key)) { | ||
key = String(key); | ||
@@ -275,6 +275,2 @@ } | ||
function isBuffer(buf) { | ||
return buf instanceof ArrayBuffer; | ||
} | ||
function checkKeyValue(obj, type) { | ||
@@ -303,3 +299,3 @@ if (obj === null || obj === undefined) { | ||
if (isBuffer(obj)) { | ||
if (Buffer.isBuffer(obj)) { | ||
if (obj.length === 0) { | ||
@@ -306,0 +302,0 @@ return new Error(type + ' cannot be an empty Buffer'); |
'use strict'; | ||
// ArrayBuffer/Uint8Array are old formats that date back to before we | ||
// had a proper browserified buffer type. they may be removed later | ||
var arrayBuffPrefix = 'ArrayBuffer:'; | ||
@@ -8,5 +10,10 @@ var arrayBuffRegex = new RegExp('^' + arrayBuffPrefix); | ||
// this is the new encoding format used going forward | ||
var bufferPrefix = 'Buff:'; | ||
var bufferRegex = new RegExp('^' + bufferPrefix); | ||
var utils = require('./utils'); | ||
var LocalStorageCore = require('./localstorage-core'); | ||
var TaskQueue = require('./taskqueue'); | ||
var d64 = require('d64'); | ||
@@ -61,6 +68,4 @@ function LocalStorage(dbname) { | ||
self.sequentialize(callback, function (callback) { | ||
if (value instanceof ArrayBuffer) { | ||
value = arrayBuffPrefix + btoa(String.fromCharCode.apply(null, value)); | ||
} else if (value instanceof Uint8Array) { | ||
value = uintPrefix + btoa(String.fromCharCode.apply(null, value)); | ||
if (Buffer.isBuffer(value)) { | ||
value = bufferPrefix + d64.encode(value); | ||
} | ||
@@ -89,3 +94,8 @@ | ||
if (typeof retval !== 'undefined') { | ||
if (arrayBuffRegex.test(retval)) { | ||
if (bufferRegex.test(retval)) { | ||
retval = d64.decode(retval.substring(bufferPrefix.length)); | ||
} else if (arrayBuffRegex.test(retval)) { | ||
// this type is kept for backwards | ||
// compatibility with older databases, but may be removed | ||
// after a major version bump | ||
retval = retval.substring(arrayBuffPrefix.length); | ||
@@ -96,2 +106,3 @@ retval = new ArrayBuffer(atob(retval).split('').map(function (c) { | ||
} else if (uintRegex.test(retval)) { | ||
// ditto | ||
retval = retval.substring(uintPrefix.length); | ||
@@ -98,0 +109,0 @@ retval = new Uint8Array(atob(retval).split('').map(function (c) { |
@@ -15,7 +15,8 @@ { | ||
], | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"main": "index.js", | ||
"dependencies": { | ||
"abstract-leveldown": "~0.12.0", | ||
"abstract-leveldown": "0.12.3", | ||
"argsarray": "0.0.1", | ||
"d64": "^1.0.0", | ||
"inherits": "^2.0.1", | ||
@@ -22,0 +23,0 @@ "tiny-queue": "0.2.0" |
Sorry, the diff of this file is not supported yet
65466
660
5
+ Addedd64@^1.0.0
+ Addedabstract-leveldown@0.12.3(transitive)
+ Addedd64@1.0.0(transitive)
- Removedabstract-leveldown@0.12.4(transitive)
Updatedabstract-leveldown@0.12.3