MCPcopy Create free account
hub / github.com/NaturalIntelligence/fast-xml-parser / ReadToEnd

Class ReadToEnd

src/cli/read.js:5–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import { Transform } from 'stream';
4
5export default class ReadToEnd extends Transform {
6 constructor(options = {}) {
7 super(options);
8 this._encoding = options.encoding || 'utf8';
9 this._buffer = '';
10 }
11
12 _transform(chunk, encoding, done) {
13 this._buffer += chunk.toString(this._encoding);
14 this.push(chunk);
15 done();
16 }
17
18 _flush(done) {
19 this.emit('complete', null, this._buffer);
20 done();
21 }
22
23 static readToEnd(stream, options, callback) {
24 if (typeof options === 'function') {
25 callback = options;
26 options = {};
27 }
28
29 const dest = new ReadToEnd(options);
30
31 stream.pipe(dest);
32
33 stream.on('error', (err) => {
34 stream.unpipe(dest);
35 callback(err);
36 });
37
38 dest.on('complete', callback);
39 dest.resume();
40
41 return dest;
42 }
43}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected