Skip to content

Commit

Permalink
1.0.2 - dont convert arraybuffers and/or typed arrays to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed May 4, 2013
1 parent 3b7aa71 commit 36d744d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ This library is best used with [browserify](http://browserify.org)

## code examples

```
var leveljs = require('level-js')
var db = leveljs('bigdata')
db.open(function onOpen() { })
```

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.

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

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

Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,18 @@ Level.prototype._approximateSize = function() {
}

var isBuffer = Level.prototype._isBuffer = function (buf) {
return buf instanceof ArrayBuffer
// TODO is there a better way to check this?
if (buf instanceof ArrayBuffer) return true
if (buf instanceof Int8Array) return true
if (buf instanceof Int16Array) return true
if (buf instanceof Int32Array) return true
if (buf instanceof Uint8Array) return true
if (buf instanceof Uint16Array) return true
if (buf instanceof Uint32Array) return true
if (buf instanceof Uint8ClampedArray) return true
if (buf instanceof Float32Array) return true
if (buf instanceof Float64Array) return true
return false
}

var checkKeyValue = Level.prototype._checkKeyValue = function (obj, type) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "level-js",
"version": "1.0.1",
"version": "1.0.2",
"description": "leveldown/leveldb library for browsers using IndexedDB",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion test-levelup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@ var leveljs = require('./')

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

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

var ary = new Uint8Array(1)
ary[0] = 1
db.put('binary', ary, function (err) {
if (err) return console.log('Ooops!', err) // some kind of I/O error
db.get('binary', function (err, value) {
if (err) return console.log('Ooops!', err) // likely the key was not found
console.log('binary', value)
})
})

var writeStream = db.createWriteStream()
writeStream.on('error', function (err) {
console.log('Oh my!', err)
Expand Down

0 comments on commit 36d744d

Please sign in to comment.