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' ;
65
76/*
87 * This filter consumes a stream of characters and emits one string per line.
@@ -28,6 +27,7 @@ class LineSplitter extends Stream {
2827 if ( this . buffer ) {
2928 this . emit ( 'data' , this . buffer ) ;
3029 }
30+ this . writable = false ;
3131 this . emit ( 'end' ) ;
3232 }
3333}
@@ -53,6 +53,7 @@ class ParagraphParser extends Stream {
5353 if ( data )
5454 this . parseLine ( data + '' ) ;
5555 this . flushParagraph ( ) ;
56+ this . writable = false ;
5657 this . emit ( 'end' ) ;
5758 }
5859
@@ -212,6 +213,7 @@ class Unwrapper extends Stream {
212213 end ( data ) {
213214 if ( data )
214215 this . write ( data ) ;
216+ this . writable = false ;
215217 this . emit ( 'end' ) ;
216218 }
217219}
@@ -273,6 +275,7 @@ class RtfGenerator extends Stream {
273275 this . write ( data ) ;
274276 if ( this . didWriteAnything )
275277 this . emitFooter ( ) ;
278+ this . writable = false ;
276279 this . emit ( 'end' ) ;
277280 }
278281
@@ -287,19 +290,14 @@ class RtfGenerator extends Stream {
287290 }
288291}
289292
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-
298293stdin . setEncoding ( 'utf-8' ) ;
299294stdin . resume ( ) ;
300295
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