Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

levelup

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

levelup - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

lib/read-stream-state.js

5

CHANGELOG.md

@@ -0,1 +1,6 @@

0.6.1 @ 1 Mar 2013
==================
* internal code cleanup & refactoring @ralphtheninja
* fix multiple iterator.end() calls in ReadStreams throwing errors (destroy() called while read/next is in progress) #82 #83 #84 @rvagg
0.6.0 @ Feb 25 2013

@@ -2,0 +7,0 @@ ===================

93

lib/levelup.js

@@ -28,15 +28,6 @@ /* Copyright (c) 2012-2013 LevelUP contributors

, getOptions = function (options, globalOptions) {
return typeof options == 'string' // just an encoding
? options = extend(
{}
, encodingOpts[options] || encodingOpts[defaultOptions.encoding]
)
: extend(extend({}, globalOptions), options)
, getCallback = function (options, callback) {
return typeof options == 'function' ? options : callback
}
, getCallback = function (options_, callback_) {
return typeof options_ == 'function' ? options_ : callback_
}
, createLevelUP = function (location, options, callback) {

@@ -58,2 +49,6 @@

, isOpening = function () { return status == 'opening' }
, keyEncoding = function (o) { return o.keyEncoding || o.encoding }
, valueEncoding = function (o) { return o.valueEncoding || o.encoding }
, dispatchError = function (error, callback) {

@@ -63,2 +58,12 @@ return callback ? callback(error) : levelup.emit('error', error)

, getOptions = function (options) {
return typeof options == 'string' // just an encoding
? extend(
{}
, encodingOpts[options] ||
encodingOpts[defaultOptions.encoding]
)
: extend(extend({}, levelup._options), options)
}
if (typeof options == 'function') {

@@ -81,3 +86,3 @@ callback = options

this._options = extend(extend({}, defaultOptions), options)
this._options = extend(extend({}, defaultOptions), options)
Object.defineProperty(this, 'location', {

@@ -153,7 +158,5 @@ value: location

LevelUP.prototype.get = function (key_, options_, callback_) {
LevelUP.prototype.get = function (key_, options, callback_) {
var callback
, options
, key
, keyEnc
, valueEnc

@@ -164,7 +167,7 @@ , err

return this.once('ready', function () {
this.get(key_, options_, callback_)
this.get(key_, options, callback_)
})
}
callback = getCallback(options_, callback_)
callback = getCallback(options, callback_)

@@ -176,6 +179,5 @@ if (!isOpen()) {

options = getOptions(options_, this._options)
keyEnc = options.keyEncoding || options.encoding
valueEnc = options.valueEncoding || options.encoding
key = toSlice[keyEnc](key_)
options = getOptions(options)
key = toSlice[keyEncoding(options)](key_)
valueEnc = valueEncoding(options)
options.asBuffer = valueEnc != 'utf8' && valueEnc != 'json'

@@ -194,5 +196,4 @@

LevelUP.prototype.put = function (key_, value_, options_, callback_) {
LevelUP.prototype.put = function (key_, value_, options, callback_) {
var callback
, options
, err

@@ -204,7 +205,7 @@ , key

return this.once('ready', function () {
this.put(key_, value_, options_, callback_)
this.put(key_, value_, options, callback_)
})
}
callback = getCallback(options_, callback_)
callback = getCallback(options, callback_)

@@ -216,5 +217,5 @@ if (!isOpen()) {

options = getOptions(options_, this._options)
key = toSlice[options.keyEncoding || options.encoding](key_)
value = toSlice[options.valueEncoding || options.encoding](value_)
options = getOptions(options)
key = toSlice[keyEncoding(options)](key_)
value = toSlice[valueEncoding(options)](value_)

@@ -233,5 +234,4 @@ this._db.put(key, value, options, function (err) {

LevelUP.prototype.del = function (key_, options_, callback_) {
LevelUP.prototype.del = function (key_, options, callback_) {
var callback
, options
, err

@@ -242,7 +242,7 @@ , key

return this.once('ready', function () {
this.del(key_, options_, callback_)
this.del(key_, options, callback_)
})
}
callback = getCallback(options_, callback_)
callback = getCallback(options, callback_)

@@ -254,4 +254,4 @@ if (!isOpen()) {

options = getOptions(options_, this._options)
key = toSlice[options.keyEncoding || options.encoding](key_)
options = getOptions(options)
key = toSlice[keyEncoding(options)](key_)

@@ -270,7 +270,6 @@ this._db.del(key, options, function (err) {

LevelUP.prototype.batch = function (arr_, options_, callback_) {
LevelUP.prototype.batch = function (arr_, options, callback_) {
var callback
, options
, keyEncoding
, valueEncoding
, keyEnc
, valueEnc
, err

@@ -281,7 +280,7 @@ , arr

return this.once('ready', function () {
this.batch(arr_, options_, callback_)
this.batch(arr_, options, callback_)
})
}
callback = getCallback(options_, callback_)
callback = getCallback(options, callback_)

@@ -293,5 +292,5 @@ if (!isOpen()) {

options = getOptions(options_, this._options)
keyEncoding = options.keyEncoding || options.encoding
valueEncoding = options.valueEncoding || options.encoding
options = getOptions(options)
keyEnc = keyEncoding(options)
valueEnc = valueEncoding(options)

@@ -301,11 +300,11 @@ // If we're not dealing with plain utf8 strings or plain

// encode the keys and/or values. This includes JSON types.
if ((keyEncoding != 'utf8' && keyEncoding != 'binary')
|| (valueEncoding != 'utf8' && valueEncoding != 'binary')) {
if ((keyEnc != 'utf8' && keyEnc != 'binary')
|| (valueEnc != 'utf8' && valueEnc != 'binary')) {
arr = arr_.map(function (e) {
if (e.type !== undefined && e.key !== undefined) {
var o = { type: e.type, key: toSlice[keyEncoding](e.key) }
var o = { type: e.type, key: toSlice[keyEnc](e.key) }
if (e.value !== undefined)
o.value = toSlice[valueEncoding](e.value)
o.value = toSlice[valueEnc](e.value)

@@ -312,0 +311,0 @@ return o

@@ -10,2 +10,3 @@ /* Copyright (c) 2012-2013 LevelUP contributors

, extend = require('util')._extend
, State = require('./read-stream-state')

@@ -32,7 +33,7 @@ , toEncoding = require('./util').toEncoding

function ReadStream (options, db, iteratorFactory) {
Stream.call(this)
this._status = 'ready'
this._state = State()
this._dataEvent = 'data'

@@ -64,5 +65,6 @@ this.readable = true

var ready = function () {
if (this._status == 'ended')
if (!this._state.canEmitData())
return
this._state.ready()
this._iterator = iteratorFactory(this._options)

@@ -82,10 +84,11 @@ this.emit('ready')

ReadStream.prototype.destroy = function () {
this._status = 'destroyed'
this._cleanup()
this._state.destroy()
if (this._state.canCleanup())
this._cleanup()
}
ReadStream.prototype.pause = function () {
if (this._status != 'ended' && !/\+paused$/.test(this._status)) {
if (this._state.canPause()) {
this._state.pause()
this.emit('pause')
this._status += '+paused' // preserve existing status
}

@@ -95,5 +98,5 @@ }

ReadStream.prototype.resume = function () {
if (this._status != 'ended') {
if (this._state.canResume()) {
this.emit('resume')
this._status = this._status.replace(/\+paused$/, '')
this._state.resume()
this._read()

@@ -123,4 +126,4 @@ }

ReadStream.prototype._read = function () {
if (this._status == 'ready') {
this._status = 'reading'
if (this._state.canRead()) {
this._state.read()
this._iterator.next(this._onData.bind(this))

@@ -131,11 +134,6 @@ }

ReadStream.prototype._onData = function (err, key, value) {
if (err)
this._state.endRead()
if (err || !arguments.length /* end */ || !this._state.canEmitData())
return this._cleanup(err)
if (!arguments.length) // end
return this._cleanup()
if (this._status == 'ended')
return
if (/^reading/.test(this._status))
this._status = this._status.replace(/^reading/, 'ready')
this._read()
this._read() // queue another read even tho we may not need it
this.emit(this._dataEvent, this._makeData(key, value))

@@ -145,7 +143,9 @@ }

ReadStream.prototype._cleanup = function (err) {
if (this._status == 'ended')
return err && this.emit('error', err)
if (err)
this.emit('error', err)
var s = this._status
this._status = 'ended'
if (!this._state.canEnd())
return
this._state.end()
this.readable = false

@@ -155,2 +155,3 @@

this._iterator.end(function () {
this._iterator = null
this.emit('close')

@@ -161,6 +162,3 @@ }.bind(this))

if (err)
this.emit('error', err)
else (s != 'destroyed')
this.emit('end')
this.emit('end')
}

@@ -167,0 +165,0 @@

@@ -24,3 +24,3 @@ {

]
, "version" : "0.6.0"
, "version" : "0.6.1"
, "main" : "lib/levelup.js"

@@ -27,0 +27,0 @@ , "dependencies" : {

@@ -15,2 +15,4 @@ LevelUP

The native LevelDB binding is now provided by a separate package, [LevelDOWN](https://github.com/rvagg/node-leveldown/).
**LevelUP** is an **OPEN Open Source Project**, see the <a href="#contributing">Contributing</a> section to find out what this means.

@@ -17,0 +19,0 @@

@@ -658,2 +658,18 @@ /* Copyright (c) 2012-2013 LevelUP contributors

}
, 'test can only end once': function (done) {
this.openTestDatabase(function (db) {
db.batch(this.sourceData.slice(), function (err) {
refute(err)
var rs = db.createReadStream()
.on('close', done)
process.nextTick(function () {
rs.destroy()
})
}.bind(this))
}.bind(this))
}
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc