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

Commit 9c32ca9

Browse files
committed
refactor read streams using level-iterator-stream and level-codec
1 parent 681c6ce commit 9c32ca9

38 files changed

Lines changed: 204 additions & 273 deletions

CHANGELOG.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
### 0.18.6 @ Aug 26 2014
1+
### 0.19.0 @ Aug 26 2014
2+
3+
* [[`7f14058440`](https://github.com/level/levelup/commit/7f14058440)] - minor whitespace changes (Rod Vagg)
4+
* [[`9e6d335df2`](https://github.com/level/levelup/commit/9e6d335df2)] - fix license (Rod Vagg)
5+
* [[`74caa18c09`](https://github.com/level/levelup/commit/74caa18c09)] - minor style fixes (Rod Vagg)
6+
* [[`1c7bc43d01`](https://github.com/level/levelup/commit/1c7bc43d01)] - update nodeico badge (Rod Vagg)
7+
* [[`b6357cc323`](https://github.com/level/levelup/commit/b6357cc323)] - Use highest/lowest instead of largest/smallest (Arnout Engelen)
8+
* [[`e45ce4e9d5`](https://github.com/level/levelup/commit/e45ce4e9d5)] - Document what 'limit' does in 'reverse' mode (Arnout Engelen)
9+
* [[`9004e9db69`](https://github.com/level/levelup/commit/9004e9db69)] - Discourage the use of start/end a bit (Arnout Engelen)
10+
* [[`6178d69cdc`](https://github.com/level/levelup/commit/6178d69cdc)] - merge (Dominic Tarr)
11+
* [[`e3ab0ebe03`](https://github.com/level/levelup/commit/e3ab0ebe03)] - document with comments (Dominic Tarr)
12+
* [[`bb88572c15`](https://github.com/level/levelup/commit/bb88572c15)] - unmention bops (Dominic Tarr)
13+
* [[`45df8e668e`](https://github.com/level/levelup/commit/45df8e668e)] - clarify ltgt (Dominic Tarr)
14+
* [[`54eba03305`](https://github.com/level/levelup/commit/54eba03305)] - binary encoding in the browser (Calvin Metcalf)
15+
16+
### 0.18.6 @ Jul 26 2014
17+
218
* (lots of stuff since 0.18.1 not recorded in changelog, ooops)
319
* Extracted encoding / codec to separate modules (@dominictarr)
420

5-
621
### 0.18.1 @ Nov 20 2013
22+
723
* Make chained-batch obey global LevelUP object options (@mcavage)
824

925
### 0.18.0 @ Nov 18 2013
@@ -54,7 +70,7 @@
5470

5571
### 0.9.0 @ 21 May 2013
5672

57-
* Use LevelDOWN@0.5.0, see https://github.com/rvagg/node-leveldown/blob/master/CHANGELOG.md for details
73+
* Use LevelDOWN@0.5.0, see https://github.com/level/leveldown/blob/master/CHANGELOG.md for details
5874
* Race-condition(ish) fixed in ReadStream--createReadStream() does not start immediately and therefore allowed put()s to happen before the stream starts (@dominictarr)
5975
* ReadStream doesn't emit "ready" event (@dominictarr)
6076
* Allow separate encodings per operation in db.batch() (@juliangruber)
@@ -98,7 +114,7 @@
98114
### 0.6.0 @ Feb 25 2013
99115

100116
* complete transition to LevelDOWN for the LevelDB binding. No native code left in LevelUP @rvagg
101-
- LevelDOWN now keeps its own ChangeLog at: https://github.com/rvagg/node-leveldown/blob/master/CHANGELOG.md
117+
- LevelDOWN now keeps its own ChangeLog at: https://github.com/level/leveldown/blob/master/CHANGELOG.md
102118
- LevelDB@1.9.0 and Snappy@1.1.0 are included in LevelDOWN@0.1.2
103119
* simplify callback signature (remove extra, undocumented properties from some callbacks) @rvagg / @dominictarr
104120

LICENSE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
The MIT License (MIT)
22
=====================
33

4-
Copyright (c) 2014 LevelUP contributors
4+
Copyright (c) 2012-2015 LevelUP contributors
55
---------------------------------------
66

7-
*LevelUP contributors listed at <https://github.com/rvagg/node-levelup#contributors>*
7+
*LevelUP contributors listed at <https://github.com/level/levelup#contributors>*
88

99
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1010

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LevelUP
55

66
**Fast & simple storage - a Node.js-style LevelDB wrapper**
77

8-
[![Build Status](https://secure.travis-ci.org/rvagg/node-levelup.png)](http://travis-ci.org/rvagg/node-levelup)
8+
[![Build Status](https://secure.travis-ci.org/Level/levelup.png)](http://travis-ci.org/Level/levelup)
99

1010
[![NPM](https://nodei.co/npm/levelup.png?stars&downloads&downloadRank)](https://nodei.co/npm/levelup/) [![NPM](https://nodei.co/npm-dl/levelup.png?months=6&height=3)](https://nodei.co/npm/levelup/)
1111

@@ -40,11 +40,11 @@ LevelDB stores entries **sorted lexicographically by keys**. This makes LevelUP'
4040
Relationship to LevelDOWN
4141
-------------------------
4242

43-
LevelUP is designed to be backed by **[LevelDOWN](https://github.com/rvagg/node-leveldown/)** which provides a pure C++ binding to LevelDB and can be used as a stand-alone package if required.
43+
LevelUP is designed to be backed by **[LevelDOWN](https://github.com/level/leveldown/)** which provides a pure C++ binding to LevelDB and can be used as a stand-alone package if required.
4444

4545
**As of version 0.9, LevelUP no longer requires LevelDOWN as a dependency so you must `npm install leveldown` when you install LevelUP.**
4646

47-
LevelDOWN is now optional because LevelUP can be used with alternative backends, such as **[level.js](https://github.com/maxogden/level.js)** in the browser or [MemDOWN](https://github.com/rvagg/node-memdown) for a pure in-memory store.
47+
LevelDOWN is now optional because LevelUP can be used with alternative backends, such as **[level.js](https://github.com/maxogden/level.js)** in the browser or [MemDOWN](https://github.com/level/memdown) for a pure in-memory store.
4848

4949
LevelUP will look for LevelDOWN and throw an error if it can't find it in its Node `require()` path. It will also tell you if the installed version of LevelDOWN is incompatible.
5050

@@ -161,7 +161,7 @@ db.get('foo', function (err, value) {
161161

162162
The `location` argument is available as a read-only property on the returned LevelUP instance.
163163

164-
The `levelup(options, callback)` form (with optional `callback`) is only available where you provide a valid `'db'` property on the options object (see below). Only for back-ends that don't require a `location` argument, such as [MemDOWN](https://github.com/rvagg/memdown).
164+
The `levelup(options, callback)` form (with optional `callback`) is only available where you provide a valid `'db'` property on the options object (see below). Only for back-ends that don't require a `location` argument, such as [MemDOWN](https://github.com/level/memdown).
165165

166166
For example:
167167

@@ -171,7 +171,7 @@ var memdown = require('memdown')
171171
var db = levelup({ db: memdown })
172172
```
173173

174-
The `levelup(db, callback)` form (with optional `callback`) is only available where `db` is a factory function, as would be provided as a `'db'` property on an `options` object (see below). Only for back-ends that don't require a `location` argument, such as [MemDOWN](https://github.com/rvagg/memdown).
174+
The `levelup(db, callback)` form (with optional `callback`) is only available where `db` is a factory function, as would be provided as a `'db'` property on an `options` object (see below). Only for back-ends that don't require a `location` argument, such as [MemDOWN](https://github.com/level/memdown).
175175

176176
For example:
177177

@@ -198,7 +198,7 @@ var db = levelup(memdown)
198198
<p>Supported encodings are: hex, utf8, ascii, binary, base64, ucs2, utf16le.</p>
199199
<p><code>'json'</code> encoding is also supported, see below.</p>
200200

201-
* `'db'` *(object, default: LevelDOWN)*: LevelUP is backed by [LevelDOWN](https://github.com/rvagg/node-leveldown/) to provide an interface to LevelDB. You can completely replace the use of LevelDOWN by providing a "factory" function that will return a LevelDOWN API compatible object given a `location` argument. For further information, see [MemDOWN](https://github.com/rvagg/node-memdown/), a fully LevelDOWN API compatible replacement that uses a memory store rather than LevelDB. Also see [Abstract LevelDOWN](http://github.com/rvagg/node-abstract-leveldown), a partial implementation of the LevelDOWN API that can be used as a base prototype for a LevelDOWN substitute.
201+
* `'db'` *(object, default: LevelDOWN)*: LevelUP is backed by [LevelDOWN](https://github.com/level/leveldown/) to provide an interface to LevelDB. You can completely replace the use of LevelDOWN by providing a "factory" function that will return a LevelDOWN API compatible object given a `location` argument. For further information, see [MemDOWN](https://github.com/level/memdown), a fully LevelDOWN API compatible replacement that uses a memory store rather than LevelDB. Also see [Abstract LevelDOWN](http://github.com/level/abstract-leveldown), a partial implementation of the LevelDOWN API that can be used as a base prototype for a LevelDOWN substitute.
202202

203203
Additionally, each of the main interface methods accept an optional options object that can be used to override `'keyEncoding'` and `'valueEncoding'`.
204204

@@ -460,11 +460,11 @@ db.createReadStream({ keys: false, values: true })
460460
<a name="writeStreams"></a>
461461
#### What happened to `db.createWriteStream`?
462462

463-
`db.createWriteStream()` has been removed in order to provide a smaller and more maintainable core. It primarily existed to create symmetry with `db.createReadStream()` but through much [discussion](https://github.com/rvagg/node-levelup/issues/199), removing it was the best cause of action.
463+
`db.createWriteStream()` has been removed in order to provide a smaller and more maintainable core. It primarily existed to create symmetry with `db.createReadStream()` but through much [discussion](https://github.com/level/levelup/issues/199), removing it was the best cause of action.
464464

465465
The main driver for this was performance. While `db.createReadStream()` performs well under most use cases, `db.createWriteStream()` was highly dependent on the application keys and values. Thus we can't provide a standard implementation and encourage more `write-stream` implementations to be created to solve the broad spectrum of use cases.
466466

467-
Check out the implementations that the community has already produced [here](https://github.com/rvagg/node-levelup/wiki/Modules#write-streams).
467+
Check out the implementations that the community has already produced [here](https://github.com/level/levelup/wiki/Modules#write-streams).
468468

469469
--------------------------------------------------------
470470
<a name='approximateSize'></a>
@@ -480,7 +480,7 @@ db.db.approximateSize('a', 'c', function (err, size) {
480480
})
481481
```
482482

483-
**Note:** `approximateSize()` is available via [LevelDOWN](https://github.com/rvagg/node-leveldown/), which by default is accessible as the `db` property of your LevelUP instance. This is a specific LevelDB operation and is not likely to be available where you replace LevelDOWN with an alternative back-end via the `'db'` option.
483+
**Note:** `approximateSize()` is available via [LevelDOWN](https://github.com/level/leveldown/), which by default is accessible as the `db` property of your LevelUP instance. This is a specific LevelDB operation and is not likely to be available where you replace LevelDOWN with an alternative back-end via the `'db'` option.
484484

485485

486486
--------------------------------------------------------
@@ -503,7 +503,7 @@ console.log(db.db.getProperty('leveldb.num-files-at-level3'))
503503
// → '243'
504504
```
505505

506-
**Note:** `getProperty()` is available via [LevelDOWN](https://github.com/rvagg/node-leveldown/), which by default is accessible as the `db` property of your LevelUP instance. This is a specific LevelDB operation and is not likely to be available where you replace LevelDOWN with an alternative back-end via the `'db'` option.
506+
**Note:** `getProperty()` is available via [LevelDOWN](https://github.com/level/leveldown/), which by default is accessible as the `db` property of your LevelUP instance. This is a specific LevelDB operation and is not likely to be available where you replace LevelDOWN with an alternative back-end via the `'db'` option.
507507

508508

509509
--------------------------------------------------------
@@ -513,7 +513,7 @@ console.log(db.db.getProperty('leveldb.num-files-at-level3'))
513513

514514
The callback will be called when the destroy operation is complete, with a possible `error` argument.
515515

516-
**Note:** `destroy()` is available via [LevelDOWN](https://github.com/rvagg/node-leveldown/) which you will have to install seperately, e.g.:
516+
**Note:** `destroy()` is available via [LevelDOWN](https://github.com/level/leveldown/) which you will have to install seperately, e.g.:
517517

518518
```js
519519
require('leveldown').destroy('./huge.db', function (err) { console.log('done!') })
@@ -532,7 +532,7 @@ A `repair()` can also be used to perform a compaction of the LevelDB log into ta
532532

533533
The callback will be called when the repair operation is complete, with a possible `error` argument.
534534

535-
**Note:** `repair()` is available via [LevelDOWN](https://github.com/rvagg/node-leveldown/) which you will have to install seperately, e.g.:
535+
**Note:** `repair()` is available via [LevelDOWN](https://github.com/level/leveldown/) which you will have to install seperately, e.g.:
536536

537537
```js
538538
require('leveldown').repair('./huge.db', function (err) { console.log('done!') })
@@ -581,7 +581,7 @@ A custom encoding may be provided by passing in an object as an value for `keyEn
581581
Extending LevelUP
582582
-----------------
583583

584-
A list of <a href="https://github.com/rvagg/node-levelup/wiki/Modules"><b>Node.js LevelDB modules and projects</b></a> can be found in the wiki.
584+
A list of <a href="https://github.com/level/levelup/wiki/Modules"><b>Node.js LevelDB modules and projects</b></a> can be found in the wiki.
585585

586586
When attempting to extend the functionality of LevelUP, it is recommended that you consider using [level-hooks](https://github.com/dominictarr/level-hooks) and/or [level-sublevel](https://github.com/dominictarr/level-sublevel). **level-sublevel** is particularly helpful for keeping additional, extension-specific, data in a LevelDB store. It allows you to partition a LevelUP instance into multiple sub-instances that each correspond to discrete namespaced key ranges.
587587

@@ -591,7 +591,7 @@ Multi-process access
591591

592592
LevelDB is thread-safe but is **not** suitable for accessing with multiple processes. You should only ever have a LevelDB database open from a single Node.js process. Node.js clusters are made up of multiple processes so a LevelUP instance cannot be shared between them either.
593593

594-
See the <a href="https://github.com/rvagg/node-levelup/wiki/Modules"><b>wiki</b></a> for some LevelUP extensions, including [multilevel](https://github.com/juliangruber/multilevel), that may help if you require a single data store to be shared across processes.
594+
See the <a href="https://github.com/level/levelup/wiki/Modules"><b>wiki</b></a> for some LevelUP extensions, including [multilevel](https://github.com/juliangruber/multilevel), that may help if you require a single data store to be shared across processes.
595595

596596
<a name="support"></a>
597597
Getting support
@@ -611,7 +611,7 @@ LevelUP is an **OPEN Open Source Project**. This means that:
611611

612612
> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.
613613
614-
See the [CONTRIBUTING.md](https://github.com/rvagg/node-levelup/blob/master/CONTRIBUTING.md) file for more details.
614+
See the [CONTRIBUTING.md](https://github.com/level/levelup/blob/master/CONTRIBUTING.md) file for more details.
615615

616616
### Contributors
617617

lib/batch.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/* Copyright (c) 2012-2014 LevelUP contributors
2-
* See list at <https://github.com/rvagg/node-levelup#contributing>
1+
/* Copyright (c) 2012-2015 LevelUP contributors
2+
* See list at <https://github.com/level/levelup#contributing>
33
* MIT License
4-
* <https://github.com/rvagg/node-levelup/blob/master/LICENSE.md>
4+
* <https://github.com/level/levelup/blob/master/LICENSE.md>
55
*/
66

77
var util = require('./util')

lib/levelup.js

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
/* Copyright (c) 2012-2014 LevelUP contributors
2-
* See list at <https://github.com/rvagg/node-levelup#contributing>
1+
/* Copyright (c) 2012-2015 LevelUP contributors
2+
* See list at <https://github.com/level/levelup#contributing>
33
* MIT License
4-
* <https://github.com/rvagg/node-levelup/blob/master/LICENSE.md>
4+
* <https://github.com/level/levelup/blob/master/LICENSE.md>
55
*/
66

77
var EventEmitter = require('events').EventEmitter
88
, inherits = require('util').inherits
99
, extend = require('xtend')
1010
, prr = require('prr')
1111
, DeferredLevelDOWN = require('deferred-leveldown')
12+
, IteratorStream = require('level-iterator-stream')
1213

1314
, errors = require('level-errors')
1415
, WriteError = errors.WriteError
@@ -18,7 +19,6 @@ var EventEmitter = require('events').EventEmitter
1819
, EncodingError = errors.EncodingError
1920
, InitializationError = errors.InitializationError
2021

21-
, ReadStream = require('./read-stream')
2222
, util = require('./util')
2323
, Batch = require('./batch')
2424
, Codec = require('level-codec')
@@ -345,48 +345,21 @@ LevelUP.prototype.approximateSize = function (start_, end_, options, callback) {
345345

346346
LevelUP.prototype.readStream =
347347
LevelUP.prototype.createReadStream = function (options) {
348-
var self = this
349348
options = extend( {keys: true, values: true}, this.options, options)
350349

351350
options.keyEncoding = options.keyEncoding
352351
options.valueEncoding = options.valueEncoding
353352

354-
if (isDefined(options.start))
355-
options.start = this._codec.encodeKey(options.start, [options])
356-
if (isDefined(options.end))
357-
options.end = this._codec.encodeKey(options.end, [options])
358-
if (isDefined(options.gte))
359-
options.gte = this._codec.encodeKey(options.gte, [options])
360-
if (isDefined(options.gt))
361-
options.gt = this._codec.encodeKey(options.gt, [options])
362-
if (isDefined(options.lte))
363-
options.lte = this._codec.encodeKey(options.lte, [options])
364-
if (isDefined(options.lt))
365-
options.lt = this._codec.encodeKey(options.lt, [options])
353+
options = this._codec.encodeLtgt(options);
354+
options.keyAsBuffer = this._codec.keyAsBuffer(options)
355+
options.valueAsBuffer = this._codec.valueAsBuffer(options)
356+
366357
if ('number' !== typeof options.limit)
367358
options.limit = -1
368359

369-
options.keyAsBuffer = this._codec.keyAsBuffer([options])
370-
options.valueAsBuffer = this._codec.valueAsBuffer([options])
371-
372-
var makeData = options.keys && options.values
373-
? function (key, value) {
374-
return {
375-
key: self._codec.decodeKey(key, [options])
376-
, value: self._codec.decodeValue(value, [options])
377-
}
378-
}
379-
: options.keys
380-
? function (key) {
381-
return self._codec.decodeKey(key, [options])
382-
}
383-
: options.values
384-
? function (_, value) {
385-
return self._codec.decodeValue(value, [options])
386-
}
387-
: function () {}
388-
389-
return new ReadStream(this.db.iterator(options), options, makeData)
360+
return new IteratorStream(this.db.iterator(options), extend(options, {
361+
decoder: this._codec.createStreamDecoder(options)
362+
}))
390363
}
391364

392365
LevelUP.prototype.keyStream =

0 commit comments

Comments
 (0)