UNPKG

1.2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.TrieReadStream = void 0;
4const nibbles_1 = require("./util/nibbles");
5const Readable = require('readable-stream').Readable;
6class TrieReadStream extends Readable {
7 constructor(trie) {
8 super({ objectMode: true });
9 this.trie = trie;
10 this._started = false;
11 }
12 async _read() {
13 if (this._started) {
14 return;
15 }
16 this._started = true;
17 try {
18 await this.trie._findValueNodes(async (nodeRef, node, key, walkController) => {
19 if (node !== null) {
20 this.push({
21 key: (0, nibbles_1.nibblesToBuffer)(key),
22 value: node.value,
23 });
24 walkController.allChildren(node, key);
25 }
26 });
27 }
28 catch (error) {
29 if (error.message == 'Missing node in DB') {
30 // pass
31 }
32 else {
33 throw error;
34 }
35 }
36 this.push(null);
37 }
38}
39exports.TrieReadStream = TrieReadStream;
40//# sourceMappingURL=readStream.js.map
\No newline at end of file