Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit 1f33d78

Browse files
authored
remove ArrayBuffer in favor of Buffer (#85)
1 parent eb9b637 commit 1f33d78

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ level.js uses [IDBWrapper](https://github.com/jensarps/IDBWrapper) by jensarps t
1212

1313
Here are the goals of this level.js:
1414

15-
- Store large amounts of ascii (strings, JSON) and binary (ArrayBuffers, Typed Arrays) data in modern browsers
15+
- Store large amounts of ascii (strings, JSON) and binary (Buffer) data in modern browsers
1616
- Be as fast as possible
1717
- Use the leveldown test suite and sync with [multilevel](https://github.com/juliangruber/multilevel) over either ascii or binary transports (websockets and xhr both have ascii/binary modes in browsers now)
1818

@@ -44,8 +44,6 @@ The test suite for this library is in the [abstract-leveldown](https://github.co
4444

4545
For more code examples see the [abstract-leveldown test suite](https://github.com/rvagg/node-abstract-leveldown/tree/master/abstract)
4646

47-
The only differences between this and leveldown is that you can store `ArrayBuffers` in this (whereas leveldown just uses node `Buffer` objects)
48-
4947
## run the tests
5048

5149
```sh

index.js

+4-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var IDB = require('idb-wrapper')
44
var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
55
var util = require('util')
66
var Iterator = require('./iterator')
7-
var isBuffer = require('isbuffer')
87
var xtend = require('xtend')
98
var toBuffer = require('typedarray-to-buffer')
109

@@ -80,15 +79,12 @@ Level.prototype._put = function (key, value, options, callback) {
8079
// - Number, except NaN. Includes Infinity and -Infinity
8180
// - Date, except invalid (NaN)
8281
// - String
83-
// - ArrayBuffer or a view thereof (typed arrays)
82+
// - ArrayBuffer or a view thereof (typed arrays). In level-js we only support
83+
// Buffer (which is an Uint8Array).
8484
// - Array, except cyclical and empty (e.g. Array(10)). Elements must be valid
8585
// types themselves.
8686
Level.prototype._serializeKey = function (key) {
87-
// TODO: do we still need to support ArrayBuffer?
88-
if (key instanceof ArrayBuffer) {
89-
key = Buffer.from(key)
90-
return Level.binaryKeys ? key : key.toString()
91-
} else if (Buffer.isBuffer(key)) {
87+
if (Buffer.isBuffer(key)) {
9288
return Level.binaryKeys ? key : key.toString()
9389
} else if (Array.isArray(key)) {
9490
return key.map(this._serializeKey, this)
@@ -100,11 +96,7 @@ Level.prototype._serializeKey = function (key) {
10096
}
10197

10298
Level.prototype._serializeValue = function (value) {
103-
// TODO: do we still need to support ArrayBuffer?
104-
if (value instanceof ArrayBuffer) return Buffer.from(value)
105-
if (value == null) return ''
106-
107-
return value
99+
return value == null ? '' : value
108100
}
109101

110102
Level.prototype._iterator = function (options) {
@@ -159,16 +151,3 @@ Level.destroy = function (db, callback) {
159151
callback(err)
160152
}
161153
}
162-
163-
var checkKeyValue = Level.prototype._checkKeyValue = function (obj, type) {
164-
if (obj === null || obj === undefined)
165-
return new Error(type + ' cannot be `null` or `undefined`')
166-
if (obj === null || obj === undefined)
167-
return new Error(type + ' cannot be `null` or `undefined`')
168-
if (isBuffer(obj) && obj.byteLength === 0)
169-
return new Error(type + ' cannot be an empty ArrayBuffer')
170-
if (String(obj) === '')
171-
return new Error(type + ' cannot be an empty String')
172-
if (obj.length === 0)
173-
return new Error(type + ' cannot be an empty Array')
174-
}

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"dependencies": {
2929
"abstract-leveldown": "~5.0.0",
3030
"idb-wrapper": "^1.5.0",
31-
"isbuffer": "~0.0.0",
3231
"ltgt": "^2.1.2",
3332
"typedarray-to-buffer": "~3.1.5",
3433
"xtend": "~4.0.1"

0 commit comments

Comments
 (0)