From 36d744dbd205bd89dbfef2b0b01f43006a178bb3 Mon Sep 17 00:00:00 2001 From: Max Ogden Date: Sat, 4 May 2013 11:35:56 -0700 Subject: [PATCH] 1.0.2 - dont convert arraybuffers and/or typed arrays to strings --- README.md | 8 +++++++- index.js | 13 ++++++++++++- package.json | 2 +- test-levelup.js | 12 +++++++++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 77e1ee4..2b78b15 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/index.js b/index.js index 1adb001..734ccce 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/package.json b/package.json index 691ac14..3042678 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test-levelup.js b/test-levelup.js index a1f72f8..fcabc55 100644 --- a/test-levelup.js +++ b/test-levelup.js @@ -6,7 +6,7 @@ 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 @@ -14,6 +14,16 @@ db.put('name', 'LevelUP', function (err) { }) }) +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)