import { countWords } from './reading-time' ; import { Transform , TransformCallback } from 'stream' ; import type { Options , WordCountStats } from './types' ; class ReadingTimeStream extends Transform { options : Options ; stats : WordCountStats ; constructor ( options = { } ) { super ( { objectMode : true } ) ; this . options = options ; this . stats = { total : 0 } ; } _transform ( chunk , encoding , callback ) { const stats = countWords ( chunk . toString ( encoding ) , this . options ) ; this . stats . total += stats . total ; callback ( ) ; } _flush ( callback ) { this . push ( this . stats ) ; callback ( ) ; } } export default ReadingTimeStream ;