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

Commit 6067bb4

Browse files
jcrugzzLars-Magnus Skog
authored andcommitted
[doc] beginning of readme adjustment
1 parent 78a06b3 commit 6067bb4

1 file changed

Lines changed: 13 additions & 100 deletions

File tree

README.md

Lines changed: 13 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ db.put('name', 'LevelUP', function (err) {
118118
* <a href="#createReadStream"><code>db.<b>createReadStream()</b></code></a>
119119
* <a href="#createKeyStream"><code>db.<b>createKeyStream()</b></code></a>
120120
* <a href="#createValueStream"><code>db.<b>createValueStream()</b></code></a>
121-
* <a href="#createWriteStream"><code>db.<b>createWriteStream()</b></code></a>
122121

123122
### Special operations exposed by LevelDOWN
124123

@@ -127,6 +126,9 @@ db.put('name', 'LevelUP', function (err) {
127126
* <a href="#destroy"><code><b>leveldown.destroy()</b></code></a>
128127
* <a href="#repair"><code><b>leveldown.repair()</b></code></a>
129128

129+
### Special Notes
130+
* <a href="#writeStreams">What happened to <code><b>db.createWriteStream()</b></code></a>
131+
130132

131133
--------------------------------------------------------
132134
<a name="ctor"></a>
@@ -189,7 +191,7 @@ var db = levelup(memdown)
189191

190192
* `'compression'` *(boolean, default: `true`)*: If `true`, all *compressible* data will be run through the Snappy compression algorithm before being stored. Snappy is very fast and shouldn't gain much speed by disabling so leave this on unless you have good reason to turn it off.
191193

192-
* `'cacheSize'` *(number, default: `8 * 1024 * 1024`)*: The size (in bytes) of the in-memory [LRU](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) cache with frequently used uncompressed block contents.
194+
* `'cacheSize'` *(number, default: `8 * 1024 * 1024`)*: The size (in bytes) of the in-memory [LRU](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) cache with frequently used uncompressed block contents.
193195

194196
* `'keyEncoding'` and `'valueEncoding'` *(string, default: `'utf8'`)*: The encoding of the keys and values passed through Node.js' `Buffer` implementation (see [Buffer#toString()](http://nodejs.org/docs/latest/api/buffer.html#buffer_buf_tostring_encoding_start_end)).
195197
<p><code>'utf8'</code> is the default encoding for both keys and values so you can simply pass in strings and expect strings from your <code>get()</code> operations. You can also pass <code>Buffer</code> objects as keys and/or values and conversion will be performed.</p>
@@ -251,7 +253,7 @@ db.get('foo', function (err, value) {
251253

252254
Encoding of the `key` object will adhere to the `'keyEncoding'` option provided to <a href="#ctor"><code>levelup()</code></a>, although you can provide alternative encoding settings in the options for `get()` (it's recommended that you stay consistent in your encoding of keys and values in a single store).
253255

254-
LevelDB will by default fill the in-memory LRU Cache with data from a call to get. Disabling this is done by setting `fillCache` to `false`.
256+
LevelDB will by default fill the in-memory LRU Cache with data from a call to get. Disabling this is done by setting `fillCache` to `false`.
255257

256258
--------------------------------------------------------
257259
<a name="del"></a>
@@ -455,104 +457,13 @@ db.createReadStream({ keys: false, values: true })
455457
```
456458

457459
--------------------------------------------------------
458-
<a name="createWriteStream"></a>
459-
### db.createWriteStream([options])
460-
461-
A **WriteStream** can be obtained by calling the `createWriteStream()` method. The resulting stream is a complete Node.js-style [Writable Stream](http://nodejs.org/docs/latest/api/stream.html#stream_writable_stream) which accepts objects with `'key'` and `'value'` pairs on its `write()` method.
462-
463-
The WriteStream will buffer writes and submit them as a `batch()` operations where writes occur *within the same tick*.
464-
465-
```js
466-
var ws = db.createWriteStream()
467-
468-
ws.on('error', function (err) {
469-
console.log('Oh my!', err)
470-
})
471-
ws.on('close', function () {
472-
console.log('Stream closed')
473-
})
474-
475-
ws.write({ key: 'name', value: 'Yuri Irsenovich Kim' })
476-
ws.write({ key: 'dob', value: '16 February 1941' })
477-
ws.write({ key: 'spouse', value: 'Kim Young-sook' })
478-
ws.write({ key: 'occupation', value: 'Clown' })
479-
ws.end()
480-
```
481-
482-
The standard `write()`, `end()`, `destroy()` and `destroySoon()` methods are implemented on the WriteStream. `'drain'`, `'error'`, `'close'` and `'pipe'` events are emitted.
483-
484-
You can specify encodings both for the whole stream and individual entries:
460+
<a name="writeStreams"></a>
461+
#### What happened to `db.createWriteStream`?
485462

486-
To set the encoding for the whole stream, provide an options object as the first parameter to `createWriteStream()` with `'keyEncoding'` and/or `'valueEncoding'`.
487-
488-
To set the encoding for an individual entry:
489-
490-
```js
491-
writeStream.write({
492-
key : new Buffer([1, 2, 3])
493-
, value : { some: 'json' }
494-
, keyEncoding : 'binary'
495-
, valueEncoding : 'json'
496-
})
497-
```
498-
499-
#### write({ type: 'put' })
500-
501-
If individual `write()` operations are performed with a `'type'` property of `'del'`, they will be passed on as `'del'` operations to the batch.
502-
503-
```js
504-
var ws = db.createWriteStream()
505-
506-
ws.on('error', function (err) {
507-
console.log('Oh my!', err)
508-
})
509-
ws.on('close', function () {
510-
console.log('Stream closed')
511-
})
512-
513-
ws.write({ type: 'del', key: 'name' })
514-
ws.write({ type: 'del', key: 'dob' })
515-
ws.write({ type: 'put', key: 'spouse' })
516-
ws.write({ type: 'del', key: 'occupation' })
517-
ws.end()
518-
```
519-
520-
#### db.createWriteStream({ type: 'del' })
521-
522-
If the *WriteStream* is created with a `'type'` option of `'del'`, all `write()` operations will be interpreted as `'del'`, unless explicitly specified as `'put'`.
523-
524-
```js
525-
var ws = db.createWriteStream({ type: 'del' })
526-
527-
ws.on('error', function (err) {
528-
console.log('Oh my!', err)
529-
})
530-
ws.on('close', function () {
531-
console.log('Stream closed')
532-
})
533-
534-
ws.write({ key: 'name' })
535-
ws.write({ key: 'dob' })
536-
// but it can be overridden
537-
ws.write({ type: 'put', key: 'spouse', value: 'Ri Sol-ju' })
538-
ws.write({ key: 'occupation' })
539-
ws.end()
540-
```
541-
542-
#### Pipes and Node Stream compatibility
543-
544-
A ReadStream can be piped directly to a WriteStream, allowing for easy copying of an entire database. A simple `copy()` operation is included in LevelUP that performs exactly this on two open databases:
545-
546-
```js
547-
function copy (srcdb, dstdb, callback) {
548-
srcdb.createReadStream().pipe(dstdb.createWriteStream()).on('close', callback)
549-
}
550-
```
551-
552-
The ReadStream is also [fstream](https://github.com/isaacs/fstream)-compatible which means you should be able to pipe to and from fstreams. So you can serialize and deserialize an entire database to a directory where keys are filenames and values are their contents, or even into a *tar* file using [node-tar](https://github.com/isaacs/node-tar). See the [fstream functional test](https://github.com/rvagg/node-levelup/blob/master/test/functional/fstream-test.js) for an example. *(Note: I'm not really sure there's a great use-case for this but it's a fun example and it helps to harden the stream implementations.)*
553-
554-
KeyStreams and ValueStreams can be treated like standard streams of raw data. If `'keyEncoding'` or `'valueEncoding'` is set to `'binary'` the `'data'` events will simply be standard Node `Buffer` objects straight out of the data store.
463+
Yes we have removed `db.createWriteStream` but not to worry, there is good reason for this. *Disclaimper*: if you are not in a stage where you are worried about performance but want a streaming interface
464+
into your database, please checkout [`level-ws`][level-ws].
555465

466+
TODO: talk about performance and multiple writeStream implementations
556467

557468
--------------------------------------------------------
558469
<a name='approximateSize'></a>
@@ -614,7 +525,7 @@ require('leveldown').destroy('./huge.db', function (err) { console.log('done!')
614525

615526
> If a DB cannot be opened, you may attempt to call this method to resurrect as much of the contents of the database as possible. Some data may be lost, so be careful when calling this function on a database that contains important information.
616527
617-
You will find information on the *repair* operation in the *LOG* file inside the store directory.
528+
You will find information on the *repair* operation in the *LOG* file inside the store directory.
618529

619530
A `repair()` can also be used to perform a compaction of the LevelDB log into table files.
620531

@@ -736,3 +647,5 @@ LevelUP is licensed under the MIT license. All rights not explicitly granted in
736647

737648
=======
738649
*LevelUP builds on the excellent work of the LevelDB and Snappy teams from Google and additional contributors. LevelDB and Snappy are both issued under the [New BSD Licence](http://opensource.org/licenses/BSD-3-Clause).*
650+
651+
[level-ws]: https://github.com/level/level-ws

0 commit comments

Comments
 (0)