1
>
/*---------------------------------------------------------------------------------------------
nodeStreams.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
import { Transform } from 'stream';
6
>
import { binaryIndexOf } from '../common/buffer.js';
7
>
8
>
/**
9
>
* A Transform stream that splits the input on the "splitter" substring.
10
>
* The resulting chunks will contain (and trail with) the splitter match.
11
>
* The last chunk when the stream ends will be emitted even if a splitter
12
>
* is not encountered.
13
>
*/
14
>
export class StreamSplitter extends Transform {
15
>
private buffer: Buffer | undefined;
16
>
private readonly splitter: Buffer | number;
17
>
private readonly spitterLen: number;
18
>
19
>
constructor(splitter: string | number | Buffer) {
20
super();
21
if (typeof splitter === 'number') {