You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-99Lines changed: 27 additions & 99 deletions
Original file line number
Diff line number
Diff line change
@@ -1,112 +1,52 @@
1
1
# level-ws
2
2
3
-
> A basic WriteStream implementation for [levelup](https://github.com/Level/levelup)
3
+
**A basic writable stream for [`abstract-level`](https://github.com/Level/abstract-level) databases, using Node.js core streams.** This is not a high-performance stream. If benchmarking shows that your particular usage does not fit then try one of the alternative writable streams that are optimized for different use cases.
4
+
5
+
> :pushpin: To instead write data using Web Streams, see [`level-web-stream`](https://github.com/Level/web-stream).
`level-ws` provides the most basic general-case WriteStream for `levelup`. It was extracted from the core `levelup` at version 0.18.0.
15
-
16
-
`level-ws` is not a high-performance WriteStream. If your benchmarking shows that your particular usage pattern and data types do not perform well with this WriteStream then you should try one of the alternative WriteStreams available for `levelup` that are optimised for different use-cases.
17
-
18
-
**If you are upgrading:** please see [`UPGRADING.md`](UPGRADING.md).
Creates a [Writable](https://nodejs.org/dist/latest-v8.x/docs/api/stream.html#stream_class_stream_writable) stream which operates in **objectMode**, accepting objects with `'key'` and `'value'` pairs on its `write()` method.
35
-
36
-
The optional `options` argument may contain:
37
-
38
-
-`type`_(string, default: `'put'`)_: Default batch operation for missing `type` property during `ws.write()`.
39
-
40
-
The WriteStream will buffer writes and submit them as a `batch()` operations where writes occur _within the same tick_.
18
+
_If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._
The standard `write()`, `end()` and `destroy()` methods are implemented on the WriteStream. `'drain'`, `'error'`, `'close'` and `'pipe'` events are emitted.
21
+
const { Level } =require('level')
22
+
constWriteStream=require('level-ws')
60
23
61
-
You can specify encodings for individual entries by setting `.keyEncoding` and/or `.valueEncoding`:
If individual `write()` operations are performed with a `'type'` property of `'del'`, they will be passed on as `'del'` operations to the batch.
31
+
ws.write({ key:'alice', value:42 })
32
+
ws.write({ key:'bob', value:7 })
73
33
74
-
```js
75
-
var ws =WriteStream(db)
34
+
// To delete entries, specify an explicit type
35
+
ws.write({ type:'del', key:'tomas' })
36
+
ws.write({ type:'put', key:'sara', value:16 })
76
37
77
-
ws.on('error', function (err) {
78
-
console.log('Oh my!', err)
79
-
})
80
-
ws.on('close', function () {
81
-
console.log('Stream closed')
82
-
})
83
-
84
-
ws.write({ type:'del', key:'name' })
85
-
ws.write({ type:'del', key:'dob' })
86
-
ws.write({ type:'put', key:'spouse' })
87
-
ws.write({ type:'del', key:'occupation' })
88
38
ws.end()
89
39
```
90
40
91
-
If the _WriteStream_ is created with a `'type'` option of `'del'`, all `write()` operations will be interpreted as `'del'`, unless explicitly specified as `'put'`.
41
+
## API
92
42
93
-
```js
94
-
var ws =WriteStream(db, { type:'del' })
43
+
### `ws = WriteStream(db[, options])`
95
44
96
-
ws.on('error', function (err) {
97
-
console.log('Oh my!', err)
98
-
})
99
-
ws.on('close', function () {
100
-
console.log('Stream closed')
101
-
})
45
+
Create a [writable stream](https://nodejs.org/dist/latest-v8.x/docs/api/stream.html#stream_class_stream_writable) that operates in object mode, accepting batch operations to be committed with `db.batch()` on each tick of the Node.js event loop. The optional `options` argument may contain:
-`type` (string, default: `'put'`): default batch operation type if not set on indididual operations.
48
+
-`maxBufferLength` (number, default `Infinity`): limit the size of batches. When exceeded, the stream will stop processing writes until the current batch has been committed.
See the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.
118
58
119
-
## Donate
120
-
121
-
Support us with a monthly donation on [Open Collective](https://opencollective.com/level) and help us continue our work. Your logo or avatar will be displayed on our 28+ [GitHub repositories](https://github.com/Level) and [npm](https://www.npmjs.com/) packages. 💖
0 commit comments