UNPKG

3.59 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Readable, ReadableOptions } from 'stream';
3/**
4 * Sandwich Options that will configure parsed data
5 */
6export interface SandwichOptions extends ReadableOptions {
7 readonly head?: string | Buffer;
8 readonly tail?: string | Buffer;
9 readonly separator?: string | Buffer;
10}
11/**
12 * Handles Readable streams requests as concatenation through data handling as
13 * well adding tags it each begin, end and between of the streams
14 */
15export declare class SandwichStream extends Readable {
16 private streamsActive;
17 private streams;
18 private newStreams;
19 private head;
20 private tail;
21 private separator;
22 private currentStream;
23 /**
24 * Initiates the SandwichStream, you can consider it also passing
25 * ReadableOptions to it
26 *
27 * @param head Pushes this content before all other content
28 * @param tail Pushes this content after all other data has been pushed
29 * @param separator Pushes this content between each stream
30 * @param remaining The other kind of options to be passed to Readable
31 * @example
32 * const ss = new SandwichStream({
33 * head: 'This at the top\n',
34 * tail: '\nThis at the bottom',
35 * separator: '\n --- \n'
36 * });
37 */
38 constructor({ head, tail, separator, ...remaining }: SandwichOptions);
39 /**
40 * Add a new Readable stream in the queue
41 *
42 * @param newStream The Readable stream
43 * @example
44 * sandwichStream.add(streamOne);
45 * sandwichStream.add(streamTwo);
46 * sandwichStream.add(streamThree);
47 * @throws An Error in case that this request was not accepted
48 * @returns This instance of Sandwich Stream
49 */
50 add(newStream: Readable): this;
51 /**
52 * Works in a similar way from the Readable read, only that this one checks
53 * for whether or not a stream is already being handled
54 * @returns This instance of Sandwich Stream
55 */
56 _read(): void;
57 /**
58 * Binds an error thrown from one of the streams being handled
59 *
60 * @param err Error to be bind
61 * @returns This instance of Sandwich Stream
62 */
63 private subStreamOnError;
64 /**
65 * Fetches the next stream to be handled
66 * @returns This instance of Sandwich Stream
67 */
68 private streamNextStream;
69 /**
70 * Verifies whether or not the stream queue has ended
71 * @returns This instance of Sandwich Stream
72 */
73 private nextStream;
74 /**
75 * Once the current stream starts to pass their data, this handles it in a
76 * less complicated way
77 * @returns This instance of Sandwich Stream
78 */
79 private bindCurrentStreamEvents;
80 /**
81 * Handles the data from a current stream once they are being streamed
82 * @returns This instance of Sandwich Stream
83 */
84 private currentStreamOnReadable;
85 /**
86 * Handles the tagging once a stream is finished
87 * @returns This instance of Sandwich Stream
88 */
89 private currentStreamOnEnd;
90 /**
91 * Adds the head tag to the Sandwich Stream
92 * @returns This instance of Sandwich Stream
93 */
94 private pushHead;
95 /**
96 * Adds the separator tag to the Sandwich Stream
97 * @returns This instance of Sandwich Stream
98 */
99 private pushSeparator;
100 /**
101 * Adds the tail tag to the Sandwich Stream
102 * @returns This instance of Sandwich Stream
103 */
104 private pushTail;
105}
106export default SandwichStream;
107//# sourceMappingURL=sandwich-stream.d.ts.map
\No newline at end of file