1
- 'use strict' ;
2
-
3
- const assert = require ( 'assert' ) ;
4
- const Stream = require ( 'stream' ) ;
5
-
1
+ import assert from 'node:assert' ;
2
+ import Stream from 'node:stream' ;
3
+ import { pipeline } from 'node:stream/promises' ;
4
+ import { stdin , stdout } from 'node:process' ;
6
5
7
6
/*
8
7
* This filter consumes a stream of characters and emits one string per line.
@@ -28,6 +27,7 @@ class LineSplitter extends Stream {
28
27
if ( this . buffer ) {
29
28
this . emit ( 'data' , this . buffer ) ;
30
29
}
30
+ this . writable = false ;
31
31
this . emit ( 'end' ) ;
32
32
}
33
33
}
@@ -53,6 +53,7 @@ class ParagraphParser extends Stream {
53
53
if ( data )
54
54
this . parseLine ( data + '' ) ;
55
55
this . flushParagraph ( ) ;
56
+ this . writable = false ;
56
57
this . emit ( 'end' ) ;
57
58
}
58
59
@@ -212,6 +213,7 @@ class Unwrapper extends Stream {
212
213
end ( data ) {
213
214
if ( data )
214
215
this . write ( data ) ;
216
+ this . writable = false ;
215
217
this . emit ( 'end' ) ;
216
218
}
217
219
}
@@ -273,6 +275,7 @@ class RtfGenerator extends Stream {
273
275
this . write ( data ) ;
274
276
if ( this . didWriteAnything )
275
277
this . emitFooter ( ) ;
278
+ this . writable = false ;
276
279
this . emit ( 'end' ) ;
277
280
}
278
281
@@ -287,19 +290,14 @@ class RtfGenerator extends Stream {
287
290
}
288
291
}
289
292
290
-
291
- const stdin = process . stdin ;
292
- const stdout = process . stdout ;
293
- const lineSplitter = new LineSplitter ( ) ;
294
- const paragraphParser = new ParagraphParser ( ) ;
295
- const unwrapper = new Unwrapper ( ) ;
296
- const rtfGenerator = new RtfGenerator ( ) ;
297
-
298
293
stdin . setEncoding ( 'utf-8' ) ;
299
294
stdin . resume ( ) ;
300
295
301
- stdin . pipe ( lineSplitter ) ;
302
- lineSplitter . pipe ( paragraphParser ) ;
303
- paragraphParser . pipe ( unwrapper ) ;
304
- unwrapper . pipe ( rtfGenerator ) ;
305
- rtfGenerator . pipe ( stdout ) ;
296
+ await pipeline (
297
+ stdin ,
298
+ new LineSplitter ( ) ,
299
+ new ParagraphParser ( ) ,
300
+ new Unwrapper ( ) ,
301
+ new RtfGenerator ( ) ,
302
+ stdout ,
303
+ ) ;
0 commit comments