1 | import { Transform } from 'stream'
|
2 | import { TransformTyped } from '../stream.model'
|
3 |
|
4 | /**
|
5 | * Transforms objectMode=false Buffers/strings into objectMode=true strings.
|
6 | *
|
7 | * Useful in this _pipeline:
|
8 | * fs.createReadStream(inputPath),
|
9 | * createUnzip(), // binary
|
10 | * transformSplit(), // string chunks, but objectMode==false
|
11 | * transformToString(), // string chunks, but objectMode==true
|
12 | */
|
13 | export function transformToString(): TransformTyped<Buffer, string> {
|
14 | return new Transform({
|
15 | objectMode: false,
|
16 | readableObjectMode: true,
|
17 | transform(chunk: Buffer, _encoding, cb) {
|
18 | // console.log(`enc: ${_encoding}`, chunk.toString())
|
19 | cb(null, chunk.toString())
|
20 | },
|
21 | })
|
22 | }
|