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

Commit 36d744d

Browse files
committed
1.0.2 - dont convert arraybuffers and/or typed arrays to strings
1 parent 3b7aa71 commit 36d744d

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ This library is best used with [browserify](http://browserify.org)
2626

2727
## code examples
2828

29+
```
30+
var leveljs = require('level-js')
31+
var db = leveljs('bigdata')
32+
db.open(function onOpen() { })
33+
```
34+
2935
The test suite for this library is in the [abstract-leveldown](https://github.com/rvagg/node-abstract-leveldown) repo and is shared between various leveldown implementations across different environments and platforms.
3036

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

3339
The only differences between this and leveldown is that you can store `ArrayBuffers` in this (whereas leveldown just uses node `Buffer` objects)
3440

index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,18 @@ Level.prototype._approximateSize = function() {
6868
}
6969

7070
var isBuffer = Level.prototype._isBuffer = function (buf) {
71-
return buf instanceof ArrayBuffer
71+
// TODO is there a better way to check this?
72+
if (buf instanceof ArrayBuffer) return true
73+
if (buf instanceof Int8Array) return true
74+
if (buf instanceof Int16Array) return true
75+
if (buf instanceof Int32Array) return true
76+
if (buf instanceof Uint8Array) return true
77+
if (buf instanceof Uint16Array) return true
78+
if (buf instanceof Uint32Array) return true
79+
if (buf instanceof Uint8ClampedArray) return true
80+
if (buf instanceof Float32Array) return true
81+
if (buf instanceof Float64Array) return true
82+
return false
7283
}
7384

7485
var checkKeyValue = Level.prototype._checkKeyValue = function (obj, type) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "level-js",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "leveldown/leveldb library for browsers using IndexedDB",
55
"main": "index.js",
66
"scripts": {

test-levelup.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ var leveljs = require('./')
66

77
window.db = levelup('foo', { db: leveljs })
88

9-
db.put('name', 'LevelUP', function (err) {
9+
db.put('name', 'LevelUP string', function (err) {
1010
if (err) return console.log('Ooops!', err) // some kind of I/O error
1111
db.get('name', function (err, value) {
1212
if (err) return console.log('Ooops!', err) // likely the key was not found
1313
console.log('name=' + value)
1414
})
1515
})
1616

17+
var ary = new Uint8Array(1)
18+
ary[0] = 1
19+
db.put('binary', ary, function (err) {
20+
if (err) return console.log('Ooops!', err) // some kind of I/O error
21+
db.get('binary', function (err, value) {
22+
if (err) return console.log('Ooops!', err) // likely the key was not found
23+
console.log('binary', value)
24+
})
25+
})
26+
1727
var writeStream = db.createWriteStream()
1828
writeStream.on('error', function (err) {
1929
console.log('Oh my!', err)

0 commit comments

Comments
 (0)