• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 /**
17 * @file
18 * @kit ArkTS
19 */
20 import { Callback } from './@ohos.base';
21 import emitter from './@ohos.events.emitter';
22
23 /**
24  * The stream module provides a comprehensive set of stream processing capabilities, including four types of streams:
25  * - Writable: streams designed for writing data to.
26  * - Readable: streams designed for reading data from.
27  * - Duplex: streams that are both readable and writable.
28  * - Transform: a specialized type of duplex stream that can modify or transform data as it's being written and read.
29  *
30  * @namespace stream
31  * @syscap SystemCapability.Utils.Lang
32  * @crossplatform
33  * @atomicservice
34  * @since arkts {'1.1':'12', '1.2':'20'}
35  * @arkts 1.1&1.2
36  */
37declare namespace stream {
38  /**
39   * The type of stream callback function.
40   *
41   * @typedef { function } StreamCb
42   * @returns { void } - The function return void
43   * @syscap SystemCapability.Utils.Lang
44   * @atomicservice
45   * @since 20
46   * @arkts 1.2
47   */
48  type StreamCb = () => void;
49  /**
50   * Streams to which data can be written.
51   *
52   * @syscap SystemCapability.Utils.Lang
53   * @crossplatform
54   * @atomicservice
55   * @since arkts {'1.1':'12', '1.2':'20'}
56   * @arkts 1.1&1.2
57   */
58  class Writable {
59    /**
60     * The Writable constructor.
61     *
62     * @syscap SystemCapability.Utils.Lang
63     * @crossplatform
64     * @atomicservice
65     * @since arkts {'1.1':'12', '1.2':'20'}
66     * @arkts 1.1&1.2
67     */
68    constructor();
69    /**
70     * writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
71     * whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
72     * does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
73     * should be called after the drain event is triggered. If the write function is called continuously,
74     * the chunk is still added to the buffer until the memory overflows
75     *
76     * @param { string | Uint8Array } [chunk] - Data to be written.
77     * @param { string } [encoding] - Encoding type.
78     * @param { Function } [callback] - Callback after writing.
79     * @returns { boolean } Write success returns true, write failure returns false.
80     * @throws { BusinessError } 401 - Parameter error. Possible causes:
81     *     1.Mandatory parameters are left unspecified;
82     *     2.Incorrect parameter types;
83     *     3.Parameter verification failed.
84     * @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
85     * @throws { BusinessError } 10200036 - The stream has been ended.
86     * @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively.
87     * @syscap SystemCapability.Utils.Lang
88     * @crossplatform
89     * @atomicservice
90     * @since 12
91     */
92    write(chunk?: string | Uint8Array, encoding?: string, callback?: Function): boolean;
93
94    /**
95     * writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
96     * whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
97     * does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
98     * should be called after the drain event is triggered. If the write function is called continuously,
99     * the chunk is still added to the buffer until the memory overflows
100     *
101     * @param { string | Uint8Array } [chunk] - Data to be written.
102     * @param { string } [encoding] - Encoding type.
103     * @param { StreamCb } [callback] - Callback after writing.
104     * @returns { boolean } Write success returns true, write failure returns false.
105     * @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
106     * @throws { BusinessError } 10200036 - The stream has been ended.
107     * @syscap SystemCapability.Utils.Lang
108     * @crossplatform
109     * @atomicservice
110     * @since 20
111     * @arkts 1.2
112     */
113    write(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): boolean;
114
115    /**
116     * Write the last chunk to Writable.
117     *
118     * @param { string | Uint8Array } [chunk] - Data to be written.
119     * @param { string } [encoding] - Encoding type.
120     * @param { Function } [callback] - Callback after writing.
121     * @returns { Writable } Returns the Writable object.
122     * @throws { BusinessError } 401 - Parameter error. Possible causes:
123     *     1.Mandatory parameters are left unspecified;
124     *     2.Incorrect parameter types;
125     *     3.Parameter verification failed.
126     * @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
127     * @syscap SystemCapability.Utils.Lang
128     * @crossplatform
129     * @atomicservice
130     * @since 12
131     */
132    end(chunk?: string | Uint8Array, encoding?: string, callback?: Function): Writable;
133
134    /**
135     * Write the last chunk to Writable.
136     *
137     * @param { string | Uint8Array } [chunk] - Data to be written.
138     * @param { string } [encoding] - Encoding type.
139     * @param { StreamCb } [callback] - Callback after writing.
140     * @returns { Writable } Returns the Writable object.
141     * @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
142     * @syscap SystemCapability.Utils.Lang
143     * @crossplatform
144     * @atomicservice
145     * @since 20
146     * @arkts 1.2
147     */
148    end(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): Writable;
149
150    /**
151     * Set the default encoding mode.
152     *
153     * @param { string } [encoding] - Encoding type.Default: utf8.
154     * @returns { boolean } Setting successful returns true, setting failed returns false.
155     * @throws { BusinessError } 401 - Parameter error. Possible causes:
156     *     1.Mandatory parameters are left unspecified;
157     *     2.Incorrect parameter types;
158     *     3.Parameter verification failed.
159     * @syscap SystemCapability.Utils.Lang
160     * @crossplatform
161     * @atomicservice
162     * @since arkts {'1.1':'12', '1.2':'20'}
163     * @arkts 1.1&1.2
164     */
165    setDefaultEncoding(encoding?: string): boolean;
166    /**
167     * After the call, all Write operations will be forced to write to the buffer instead of being flushed.
168     *
169     * @returns { boolean } Setting successful returns true, setting failed returns false.
170     * @syscap SystemCapability.Utils.Lang
171     * @crossplatform
172     * @atomicservice
173     * @since arkts {'1.1':'12', '1.2':'20'}
174     * @arkts 1.1&1.2
175     */
176    cork(): boolean;
177    /**
178     * After calling, flush all buffers.
179     *
180     * @returns { boolean } Setting successful returns true, setting failed returns false.
181     * @syscap SystemCapability.Utils.Lang
182     * @crossplatform
183     * @atomicservice
184     * @since arkts {'1.1':'12', '1.2':'20'}
185     * @arkts 1.1&1.2
186     */
187    uncork(): boolean;
188    /**
189     * Registering Event Messages.
190     *
191     * @param { string } event - Register Event.
192     * @param { Callback<emitter.EventData> } callback - event callbacks.
193     * @throws { BusinessError } 401 - Parameter error. Possible causes:
194     *     1.Mandatory parameters are left unspecified;
195     *     2.Incorrect parameter types;
196     *     3.Parameter verification failed.
197     * @syscap SystemCapability.Utils.Lang
198     * @crossplatform
199     * @atomicservice
200     * @since arkts {'1.1':'12', '1.2':'20'}
201     * @arkts 1.1&1.2
202     */
203    on(event: string, callback: Callback<emitter.EventData>): void;
204    /**
205     * Cancel event message.
206     *
207     * @param { string } event - Register Event.
208     * @param { Callback<emitter.EventData> } callback - event callbacks.
209     * @throws { BusinessError } 401 - Parameter error. Possible causes:
210     *     1.Mandatory parameters are left unspecified;
211     *     2.Incorrect parameter types.
212     * @syscap SystemCapability.Utils.Lang
213     * @crossplatform
214     * @atomicservice
215     * @since arkts {'1.1':'12', '1.2':'20'}
216     * @arkts 1.1&1.2
217     */
218    off(event: string, callback?: Callback<emitter.EventData>): void;
219    /**
220     * This method is invoked by the Writable method during initialization and must not be invoked directly.
221     * After the resource is initialized in the doInitialize method, the callback () method is invoked.
222     *
223     * @param { Function } callback - Callback when the stream has completed the initial.
224     * @throws { BusinessError } 401 - Parameter error. Possible causes:
225     *     1.Mandatory parameters are left unspecified;
226     *     2.Incorrect parameter types.
227     * @syscap SystemCapability.Utils.Lang
228     * @crossplatform
229     * @atomicservice
230     * @since 12
231     */
232    doInitialize(callback: Function): void;
233
234    /**
235     * This method is invoked by the Writable method during initialization and must not be invoked directly.
236     * After the resource is initialized in the doInitialize method, the callback () method is invoked.
237     *
238     * @param { StreamCb } callback - Callback when the stream has completed the initial.
239     * @syscap SystemCapability.Utils.Lang
240     * @crossplatform
241     * @atomicservice
242     * @since 20
243     * @arkts 1.2
244     */
245    doInitialize(callback: StreamCb): void;
246
247    /**
248     * Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
249     * directly called. The call is controlled by Writable.write.
250     *
251     * @param { string | Uint8Array } chunk - Data to be written.
252     * @param { string } encoding - Encoding type.
253     * @param { Function } callback - Callback after writing.
254     * @throws { BusinessError } 401 - Parameter error. Possible causes:
255     *     1.Mandatory parameters are left unspecified;
256     *     2.Incorrect parameter types;
257     *     3.Parameter verification failed.
258     * @syscap SystemCapability.Utils.Lang
259     * @crossplatform
260     * @atomicservice
261     * @since 12
262     */
263    doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void;
264    /**
265     * Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
266     * directly called. The call is controlled by Writable.write.
267     *
268     * @param { string | Uint8Array } chunk - Data to be written.
269     * @param { string } encoding - Encoding type.
270     * @param { StreamCb } callback - Callback after writing.
271     * @syscap SystemCapability.Utils.Lang
272     * @crossplatform
273     * @atomicservice
274     * @since 20
275     * @arkts 1.2
276     */
277    doWrite(chunk: string | Uint8Array, encoding: string, callback: StreamCb): void;
278    /**
279     * The implementation logic of flushing chunks in the buffer in batches should not be actively called.
280     * The call is controlled by Writable.write.
281     *
282     * @param { string[] | Uint8Array[] } chunks - Data to be written.
283     * @param { Function } callback - Callback after writing.
284     * @throws { BusinessError } 401 - Parameter error. Possible causes:
285     *     1.Mandatory parameters are left unspecified;
286     *     2.Incorrect parameter types;
287     *     3.Parameter verification failed.
288     * @syscap SystemCapability.Utils.Lang
289     * @crossplatform
290     * @atomicservice
291     * @since 12
292     */
293    doWritev(chunks: string[] | Uint8Array[], callback: Function): void;
294    /**
295     * The implementation logic of flushing chunks in the buffer in batches should not be actively called.
296     * The call is controlled by Writable.write.
297     *
298     * @param { string[] | Uint8Array[] } chunks - Data to be written.
299     * @param { StreamCb } callback - Callback after writing.
300     * @syscap SystemCapability.Utils.Lang
301     * @crossplatform
302     * @atomicservice
303     * @since 20
304     * @arkts 1.2
305     */
306    doWritev(chunks: string[] | Uint8Array[], callback: StreamCb): void;
307
308    /**
309     * Returns boolean indicating whether it is in ObjectMode.
310     *
311     * @type { boolean }
312     * @readonly
313     * @syscap SystemCapability.Utils.Lang
314     * @crossplatform
315     * @atomicservice
316     * @since arkts {'1.1':'12', '1.2':'20'}
317     * @arkts 1.1&1.2
318     */
319    readonly writableObjectMode: boolean;
320    /**
321     * Value of highWatermark.
322     *
323     * @type { number }
324     * @readonly
325     * @syscap SystemCapability.Utils.Lang
326     * @crossplatform
327     * @atomicservice
328     * @since arkts {'1.1':'12', '1.2':'20'}
329     * @arkts 1.1&1.2
330     */
331    readonly writableHighWatermark: number;
332    /**
333     * Is true if it is safe to call writable.write(), which means the stream has not been destroyed, error or end.
334     *
335     * @type { boolean }
336     * @readonly
337     * @syscap SystemCapability.Utils.Lang
338     * @crossplatform
339     * @atomicservice
340     * @since arkts {'1.1':'12', '1.2':'20'}
341     * @arkts 1.1&1.2
342     */
343    readonly writable: boolean;
344    /**
345     * Size of data that can be flushed, in bytes or objects.
346     *
347     * @type { number }
348     * @readonly
349     * @syscap SystemCapability.Utils.Lang
350     * @crossplatform
351     * @atomicservice
352     * @since arkts {'1.1':'12', '1.2':'20'}
353     * @arkts 1.1&1.2
354     */
355    readonly writableLength: number;
356    /**
357     * Number of times writable.uncork() needs to be called in order to fully uncork the stream.
358     *
359     * @type { number }
360     * @readonly
361     * @syscap SystemCapability.Utils.Lang
362     * @crossplatform
363     * @atomicservice
364     * @since arkts {'1.1':'12', '1.2':'20'}
365     * @arkts 1.1&1.2
366     */
367    readonly writableCorked: number;
368    /**
369     * Whether Writable.end has been called.
370     *
371     * @type { boolean }
372     * @readonly
373     * @syscap SystemCapability.Utils.Lang
374     * @crossplatform
375     * @atomicservice
376     * @since arkts {'1.1':'12', '1.2':'20'}
377     * @arkts 1.1&1.2
378     */
379    readonly writableEnded: boolean;
380    /**
381     * Whether Writable.end has been called and all buffers have been flushed.
382     *
383     * @type { boolean }
384     * @readonly
385     * @syscap SystemCapability.Utils.Lang
386     * @crossplatform
387     * @atomicservice
388     * @since arkts {'1.1':'12', '1.2':'20'}
389     * @arkts 1.1&1.2
390     */
391    readonly writableFinished: boolean;
392  }
393  /**
394   * Transform stream is a Duplex stream where the output is computed in some way from the input.
395   * Transform implementations must implement the doTransform() method and may also implement the doFlush() method.
396   *
397   * @extends Duplex
398   * @syscap SystemCapability.Utils.Lang
399   * @crossplatform
400   * @atomicservice
401   * @since arkts {'1.1':'12', '1.2':'20'}
402   * @arkts 1.1&1.2
403   */
404  class Transform extends Duplex {
405    /**
406     * The Transform constructor.
407     *
408     * @syscap SystemCapability.Utils.Lang
409     * @crossplatform
410     * @atomicservice
411     * @since arkts {'1.1':'12', '1.2':'20'}
412     * @arkts 1.1&1.2
413     */
414    constructor();
415    /**
416     * Convert the input data. After the conversion, Transform.push can be called to send the input to the read stream.
417     * Transform.push should not be called Transform.write to call.
418     *
419     * @param { string } chunk - Input data to be converted.
420     * @param { string } encoding - If the chunk is a string, then this is the encoding type. If chunk is a buffer,
421     * then this is the special value 'buffer'. Ignore it in that case.
422     * @param { Function } callback - Callback after conversion.
423     * @throws { BusinessError } 401 - Parameter error. Possible causes:
424     *     1.Mandatory parameters are left unspecified;
425     *     2.Incorrect parameter types;
426     *     3.Parameter verification failed.
427     * @syscap SystemCapability.Utils.Lang
428     * @crossplatform
429     * @atomicservice
430     * @since 12
431     */
432    doTransform(chunk: string, encoding: string, callback: Function): void;
433
434    /**
435     * Convert the input data. After the conversion, Transform.push can be called to send the input to the read stream.
436     * Transform.push should not be called Transform.write to call.
437     *
438     * @param { string } chunk - Input data to be converted.
439     * @param { string } encoding - If the chunk is a string, then this is the encoding type. If chunk is a buffer,
440     * then this is the special value 'buffer'. Ignore it in that case.
441     * @param { StreamCb } callback - Callback after conversion.
442     * @syscap SystemCapability.Utils.Lang
443     * @crossplatform
444     * @atomicservice
445     * @since 20
446     * @arkts 1.2
447     */
448    doTransform(chunk: string, encoding: string, callback: StreamCb): void;
449
450    /**
451     * After all data is flushed to the write stream, you can use the Transform.doFlush writes some extra data, must
452     * not be called directly, only called by Writable after flushing all data.
453     *
454     * @param { Function } callback - Callback after flush completion.
455     * @throws { BusinessError } 401 - Parameter error. Possible causes:
456     *     1.Mandatory parameters are left unspecified;
457     *     2.Incorrect parameter types;
458     *     3.Parameter verification failed.
459     * @syscap SystemCapability.Utils.Lang
460     * @crossplatform
461     * @atomicservice
462     * @since 12
463     */
464    doFlush(callback: Function): void;
465
466    /**
467     * After all data is flushed to the write stream, you can use the Transform.doFlush writes some extra data, must
468     * not be called directly, only called by Writable after flushing all data.
469     *
470     * @param { StreamCb } callback - Callback after flush completion.
471     * @syscap SystemCapability.Utils.Lang
472     * @crossplatform
473     * @atomicservice
474     * @since 20
475     * @arkts 1.2
476     */
477    doFlush(callback: StreamCb): void;
478
479  }
480
481  /**
482   * Return readable options.
483   *
484   * @interface ReadableOptions
485   * @syscap SystemCapability.Utils.Lang
486   * @crossplatform
487   * @atomicservice
488   * @since arkts {'1.1':'12', '1.2':'20'}
489   * @arkts 1.1&1.2
490   */
491  interface ReadableOptions {
492    /**
493    * Specifies the encoding format of the data. If this parameter is provided,
494    * the readable stream decodes the data into a string in the specified encoding format. Default: utf8.
495    * If an invalid string is entered, a 401 exception is thrown in the Readable constructor.
496    * Supported encoding formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6,
497    * iso-8859-7, iso-8859-8, iso-8859-8-i, iso-8859-10, iso-8859-13, iso-8859-14, iso-8859-15, koi8-r, koi8-u,
498    * macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255,
499    * windows-1256, windows-1257, windows-1258, x-mac-cyrillic, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis,
500    * euc-kr, utf-16be, utf-16le.
501    *
502    * @type { ?string }
503    * @syscap SystemCapability.Utils.Lang
504    * @crossplatform
505    * @atomicservice
506    * @since arkts {'1.1':'12', '1.2':'20'}
507    * @arkts 1.1&1.2
508    */
509    encoding?: string;
510  }
511
512  /**
513   * The stream from which data can be read.
514   *
515   * @syscap SystemCapability.Utils.Lang
516   * @crossplatform
517   * @atomicservice
518   * @since arkts {'1.1':'12', '1.2':'20'}
519   * @arkts 1.1&1.2
520   */
521   class Readable {
522    /**
523     * The Readable constructor.
524     *
525     * @syscap SystemCapability.Utils.Lang
526     * @crossplatform
527     * @atomicservice
528     * @since arkts {'1.1':'12', '1.2':'20'}
529     * @arkts 1.1&1.2
530     */
531    constructor();
532    /**
533     * The Readable constructor.
534     *
535     * @param { ReadableOptions } options - Provide options.
536     * @throws { BusinessError } 401 - Parameter error. Possible causes:
537     *     1.Mandatory parameters are left unspecified;
538     *     2.Incorrect parameter types;
539     *     3.Parameter verification failed.
540     * @syscap SystemCapability.Utils.Lang
541     * @crossplatform
542     * @atomicservice
543     * @since arkts {'1.1':'12', '1.2':'20'}
544     * @arkts 1.1&1.2
545     */
546    constructor(options: ReadableOptions);
547    /**
548     * Reads a buffer of a specified size from the buffer. If the available buffer is sufficient, the result
549     * of the specified size is returned. Otherwise, if Readable has ended, all remaining buffers are returned.
550     *
551     * @param { number } size - Expected length of the data to be read.
552     * @returns { string | null } If no data is available to read, null is returned.
553     * @throws { BusinessError } 401 - Parameter error. Possible causes:
554     *     1.Mandatory parameters are left unspecified;
555     *     2.Incorrect parameter types;
556     *     3.Parameter verification failed.
557     * @throws { BusinessError } 10200038 - The doRead method has not been implemented.
558     * @syscap SystemCapability.Utils.Lang
559     * @crossplatform
560     * @atomicservice
561     * @since arkts {'1.1':'12', '1.2':'20'}
562     * @arkts 1.1&1.2
563     */
564    read(size?: number): string | null;
565    /**
566     * Switch Readable to Streaming Mode.
567     *
568     * @returns { Readable } Return this object.
569     * @syscap SystemCapability.Utils.Lang
570     * @crossplatform
571     * @atomicservice
572     * @since arkts {'1.1':'12', '1.2':'20'}
573     * @arkts 1.1&1.2
574     */
575    resume(): Readable;
576    /**
577     * Toggle Readable to Suspend Mode.
578     *
579     * @returns { Readable } Return this object.
580     * @syscap SystemCapability.Utils.Lang
581     * @crossplatform
582     * @atomicservice
583     * @since arkts {'1.1':'12', '1.2':'20'}
584     * @arkts 1.1&1.2
585     */
586    pause(): Readable;
587    /**
588     * Sets the encoding format of the input binary data.Default: utf8.
589     *
590     * @param { string } [encoding] - Original Data Encoding Type.
591     * @returns { boolean } Setting successful returns true, setting failed returns false.
592     * @throws { BusinessError } 401 - Parameter error. Possible causes:
593     *     1.Mandatory parameters are left unspecified;
594     *     2.Incorrect parameter types.
595     * @syscap SystemCapability.Utils.Lang
596     * @crossplatform
597     * @atomicservice
598     * @since arkts {'1.1':'12', '1.2':'20'}
599     * @arkts 1.1&1.2
600     */
601    setEncoding(encoding?: string): boolean;
602    /**
603     * Query whether it is in pause state.
604     *
605     * @returns { boolean } Pause state returns true, otherwise returns false.
606     * @syscap SystemCapability.Utils.Lang
607     * @crossplatform
608     * @atomicservice
609     * @since arkts {'1.1':'12', '1.2':'20'}
610     * @arkts 1.1&1.2
611     */
612    isPaused(): boolean;
613    /**
614     * Concatenated a Writable to a Readable and switches the Readable to stream mode.
615     *
616     * @param { Writable } destination - Output writable stream.
617     * @param { Object } [options] - Pipeline Options.
618     * @returns { Writable } Returns the Writable object.
619     * @throws { BusinessError } 401 - Parameter error. Possible causes:
620     *     1.Mandatory parameters are left unspecified;
621     *     2.Incorrect parameter types;
622     *     3.Parameter verification failed.
623     * @syscap SystemCapability.Utils.Lang
624     * @crossplatform
625     * @atomicservice
626     * @since arkts {'1.1':'12', '1.2':'20'}
627     * @arkts 1.1&1.2
628     */
629    pipe(destination: Writable, options?: Object): Writable;
630    /**
631     * Disconnect Writable from Readable.
632     *
633     * @param { Writable } [destination] - Writable Streams Needing to Be Disconnected.
634     * @returns { Readable } Returns the Readable object.
635     * @throws { BusinessError } 401 - Parameter error. Possible causes:
636     *     1.Mandatory parameters are left unspecified;
637     *     2.Incorrect parameter types;
638     *     3.Parameter verification failed.
639     * @syscap SystemCapability.Utils.Lang
640     * @crossplatform
641     * @atomicservice
642     * @since arkts {'1.1':'12', '1.2':'20'}
643     * @arkts 1.1&1.2
644     */
645    unpipe(destination?: Writable): Readable;
646    /**
647     * Registering Event Messages.
648     *
649     * @param { string } event - Registering Events.
650     * @param { Callback<emitter.EventData> } callback - Event callback.
651     * @throws { BusinessError } 401 - Parameter error. Possible causes:
652     *     1.Mandatory parameters are left unspecified;
653     *     2.Incorrect parameter types.
654     * @syscap SystemCapability.Utils.Lang
655     * @crossplatform
656     * @atomicservice
657     * @since arkts {'1.1':'12', '1.2':'20'}
658     * @arkts 1.1&1.2
659     */
660    on(event: string, callback: Callback<emitter.EventData>): void;
661    /**
662     * Cancel event message.
663     *
664     * @param { string } event - Registering Events.
665     * @param { Callback<emitter.EventData> } callback - Event callback.
666     * @throws { BusinessError } 401 - Parameter error. Possible causes:
667     *     1.Mandatory parameters are left unspecified;
668     *     2.Incorrect parameter types.
669     * @syscap SystemCapability.Utils.Lang
670     * @crossplatform
671     * @atomicservice
672     * @since arkts {'1.1':'12', '1.2':'20'}
673     * @arkts 1.1&1.2
674     */
675    off(event: string, callback?: Callback<emitter.EventData>): void;
676    /**
677     * It may be implemented by child classes, and if so, will be called by the Readable class methods only.
678     * It must not be called directly.
679     *
680     * @param { Function } callback - Callback when the stream has completed the initial.
681     * @throws { BusinessError } 401 - Parameter error. Possible causes:
682     *     1.Mandatory parameters are left unspecified;
683     *     2.Incorrect parameter types;
684     *     3.Parameter verification failed.
685     * @syscap SystemCapability.Utils.Lang
686     * @crossplatform
687     * @atomicservice
688     * @since 12
689     */
690    doInitialize(callback: Function): void;
691
692    /**
693     * It may be implemented by child classes, and if so, will be called by the Readable class methods only.
694     * It must not be called directly.
695     *
696     * @param { StreamCb } callback - Callback when the stream has completed the initial.
697     * @syscap SystemCapability.Utils.Lang
698     * @crossplatform
699     * @atomicservice
700     * @since 20
701     * @arkts 1.2
702     */
703    doInitialize(callback: StreamCb): void;
704
705    /**
706     * The specific implementation of data production. It must not be actively called.
707     * After data production, Readable.push should be called to push the produced data into the buffer.
708     * If push is not called, doRead will not be called again.
709     *
710     * @param { number } size - Expected length of the data to be read.
711     * @throws { BusinessError } 401 - Parameter error. Possible causes:
712     *     1.Mandatory parameters are left unspecified;
713     *     2.Incorrect parameter types;
714     *     3.Parameter verification failed.
715     * @syscap SystemCapability.Utils.Lang
716     * @crossplatform
717     * @atomicservice
718     * @since arkts {'1.1':'12', '1.2':'20'}
719     * @arkts 1.1&1.2
720     */
721    doRead(size: number): void;
722    /**
723     * Adds the generated data to the buffer. The return value indicates whether the data in the buffer has not
724     * reached the highWaterMark (similar to Writable.write). If the chunk is null, all data has been generated.
725     *
726     * @param {  Uint8Array | string | null } chunk - Binary data to be stored in the buffer.
727     * @param { string } [encoding] - Binary data encoding type.
728     * @returns { boolean } If true is returned, the data in the buffer reaches the highWaterMark. Otherwise, the
729     * data in the buffer does not reach the highWaterMark.
730     * @throws { BusinessError } 401 - Parameter error. Possible causes:
731     *     1.Mandatory parameters are left unspecified;
732     *     2.Incorrect parameter types.
733     * @syscap SystemCapability.Utils.Lang
734     * @crossplatform
735     * @atomicservice
736     * @since arkts {'1.1':'12', '1.2':'20'}
737     * @arkts 1.1&1.2
738     */
739    push(chunk: Uint8Array | string | null, encoding?: string): boolean;
740    /**
741     * Returns boolean indicating whether it is in ObjectMode.
742     *
743     * @type { boolean }
744     * @readonly
745     * @syscap SystemCapability.Utils.Lang
746     * @crossplatform
747     * @atomicservice
748     * @since arkts {'1.1':'12', '1.2':'20'}
749     * @arkts 1.1&1.2
750     */
751    readonly readableObjectMode: boolean;
752    /**
753     * Is true if it is safe to call readable.read(), which means
754     * the stream has not been destroyed or emitted 'error' or 'end'.
755     *
756     * @type { boolean }
757     * @readonly
758     * @syscap SystemCapability.Utils.Lang
759     * @crossplatform
760     * @atomicservice
761     * @since arkts {'1.1':'12', '1.2':'20'}
762     * @arkts 1.1&1.2
763     */
764    readonly readable: boolean;
765    /**
766     * Returns the value of highWatermark passed when creating this Readable.
767     *
768     * @type { number }
769     * @readonly
770     * @syscap SystemCapability.Utils.Lang
771     * @crossplatform
772     * @atomicservice
773     * @since arkts {'1.1':'12', '1.2':'20'}
774     * @arkts 1.1&1.2
775     */
776    readonly readableHighWatermark: number;
777    /**
778     * This property reflects the current state of the readable stream null/true/false.
779     *
780     * @type { boolean | null }
781     * @readonly
782     * @syscap SystemCapability.Utils.Lang
783     * @crossplatform
784     * @atomicservice
785     * @since arkts {'1.1':'12', '1.2':'20'}
786     * @arkts 1.1&1.2
787     */
788    readonly readableFlowing: boolean | null;
789    /**
790     * Size of the data that can be read, in bytes or objects.
791     *
792     * @type { number }
793     * @readonly
794     * @syscap SystemCapability.Utils.Lang
795     * @crossplatform
796     * @atomicservice
797     * @since arkts {'1.1':'12', '1.2':'20'}
798     * @arkts 1.1&1.2
799     */
800    readonly readableLength: number;
801    /**
802     * Getter for the property encoding of a given Readable stream. The encoding property can be set using the
803     * readable.setEncoding() method.
804     *
805     * @type { string | null }
806     * @readonly
807     * @syscap SystemCapability.Utils.Lang
808     * @crossplatform
809     * @atomicservice
810     * @since arkts {'1.1':'12', '1.2':'20'}
811     * @arkts 1.1&1.2
812     */
813    readonly readableEncoding: string | null;
814    /**
815     * Whether all data has been generated.
816     *
817     * @type { boolean }
818     * @readonly
819     * @syscap SystemCapability.Utils.Lang
820     * @crossplatform
821     * @atomicservice
822     * @since arkts {'1.1':'12', '1.2':'20'}
823     * @arkts 1.1&1.2
824     */
825    readonly readableEnded: boolean;
826  }
827  /**
828   * Duplex streams are streams that implement both the Readable streams and Writable streams interfaces.
829   *
830   * @extends Readable
831   * @syscap SystemCapability.Utils.Lang
832   * @crossplatform
833   * @atomicservice
834   * @since arkts {'1.1':'12', '1.2':'20'}
835   * @arkts 1.1&1.2
836   */
837  class Duplex extends Readable {
838    /**
839    * The Duplex constructor.
840     *
841     * @syscap SystemCapability.Utils.Lang
842     * @crossplatform
843     * @atomicservice
844     * @since arkts {'1.1':'12', '1.2':'20'}
845     * @arkts 1.1&1.2
846     */
847    constructor();
848    /**
849     * writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
850     * whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
851     * does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
852     * should be called after the drain event is triggered. If the write function is called continuously,
853     * the chunk is still added to the buffer until the memory overflows
854     *
855     * @param { string | Uint8Array } [chunk] - Data to be written.
856     * @param { string } [encoding] - Encoding type.
857     * @param { Function } [callback] - Callback after writing.
858     * @returns { boolean } Write success returns true, write failure returns false.
859     * @throws { BusinessError } 401 - Parameter error. Possible causes:
860     *     1.Mandatory parameters are left unspecified;
861     *     2.Incorrect parameter types;
862     *     3.Parameter verification failed.
863     * @throws { BusinessError } 10200036 - The stream has been ended.
864     * @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively.
865     * @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
866     * @syscap SystemCapability.Utils.Lang
867     * @crossplatform
868     * @atomicservice
869     * @since 12
870     */
871    write(chunk?: string | Uint8Array, encoding?: string, callback?: Function): boolean;
872
873    /**
874     * writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
875     * whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
876     * does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
877     * should be called after the drain event is triggered. If the write function is called continuously,
878     * the chunk is still added to the buffer until the memory overflows
879     *
880     * @param { string | Uint8Array } [chunk] - Data to be written.
881     * @param { string } [encoding] - Encoding type.
882     * @param { StreamCb } [callback] - Callback after writing.
883     * @returns { boolean } Write success returns true, write failure returns false.
884     * @throws { BusinessError } 10200036 - The stream has been ended.
885     * @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively.
886     * @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
887     * @syscap SystemCapability.Utils.Lang
888     * @crossplatform
889     * @atomicservice
890     * @since 20
891     * @arkts 1.2
892     */
893    write(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): boolean;
894
895    /**
896     * Write the last chunk to Writable.
897     *
898     * @param { string | Uint8Array } [chunk] - Data to be written.
899     * @param { string } [encoding] - Encoding type.
900     * @param { Function } [callback] - Callback after writing.
901     * @returns { Writable } Returns the Writable object.
902     * @throws { BusinessError } 401 - Parameter error. Possible causes:
903     *     1.Mandatory parameters are left unspecified;
904     *     2.Incorrect parameter types;
905     *     3.Parameter verification failed.
906     * @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
907     * @syscap SystemCapability.Utils.Lang
908     * @crossplatform
909     * @atomicservice
910     * @since 12
911     */
912    end(chunk?: string | Uint8Array, encoding?: string, callback?: Function): Writable;
913
914    /**
915     * Write the last chunk to Writable.
916     *
917     * @param { string | Uint8Array } [chunk] - Data to be written.
918     * @param { string } [encoding] - Encoding type.
919     * @param { StreamCb } [callback] - Callback after writing.
920     * @returns { Writable } Returns the Writable object.
921     * @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
922     * @syscap SystemCapability.Utils.Lang
923     * @crossplatform
924     * @atomicservice
925     * @since 20
926     * @arkts 1.2
927     */
928    end(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): Writable;
929
930    /**
931     * Set the default encoding mode.
932     *
933     * @param { string } [encoding] - Encoding type.Default: utf8.
934     * @returns { boolean } Setting successful returns true, setting failed returns false.
935     * @throws { BusinessError } 401 - Parameter error. Possible causes:
936     *     1.Mandatory parameters are left unspecified;
937     *     2.Incorrect parameter types;
938     *     3.Parameter verification failed.
939     * @syscap SystemCapability.Utils.Lang
940     * @crossplatform
941     * @atomicservice
942     * @since arkts {'1.1':'12', '1.2':'20'}
943     * @arkts 1.1&1.2
944     */
945    setDefaultEncoding(encoding?: string): boolean;
946    /**
947     * After the call, all Write operations will be forced to write to the buffer instead of being flushed.
948     *
949     * @returns { boolean } Setting successful returns true, setting failed returns false.
950     * @syscap SystemCapability.Utils.Lang
951     * @crossplatform
952     * @atomicservice
953     * @since arkts {'1.1':'12', '1.2':'20'}
954     * @arkts 1.1&1.2
955     */
956    cork(): boolean;
957    /**
958     * After calling, flush all buffers.
959     *
960     * @returns { boolean } Setting successful returns true, setting failed returns false.
961     * @syscap SystemCapability.Utils.Lang
962     * @crossplatform
963     * @atomicservice
964     * @since arkts {'1.1':'12', '1.2':'20'}
965     * @arkts 1.1&1.2
966     */
967    uncork(): boolean;
968    /**
969     * Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
970     * directly called. The call is controlled by Writable.write.
971     *
972     * @param { string | Uint8Array } chunk - Data to be written.
973     * @param { string } encoding - Encoding type.
974     * @param { Function } callback - Callback after writing.
975     * @throws { BusinessError } 401 - Parameter error. Possible causes:
976     *     1.Mandatory parameters are left unspecified;
977     *     2.Incorrect parameter types;
978     *     3.Parameter verification failed.
979     * @syscap SystemCapability.Utils.Lang
980     * @crossplatform
981     * @atomicservice
982     * @since 12
983     */
984    doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void;
985
986    /**
987     * Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
988     * directly called. The call is controlled by Writable.write.
989     *
990     * @param { string | Uint8Array } chunk - Data to be written.
991     * @param { string } encoding - Encoding type.
992     * @param { StreamCb } callback - Callback after writing.
993     * @syscap SystemCapability.Utils.Lang
994     * @crossplatform
995     * @atomicservice
996     * @since 20
997     * @arkts 1.2
998     */
999    doWrite(chunk: string | Uint8Array, encoding: string, callback: StreamCb): void;
1000
1001    /**
1002     * The implementation logic of flushing chunks in the buffer in batches should not be actively called.
1003     * The call is controlled by Writable.write.
1004     *
1005     * @param { string[] | Uint8Array[] } chunks - Data to be written.
1006     * @param { Function } callback - Callback after writing.
1007     * @throws { BusinessError } 401 - Parameter error. Possible causes:
1008     *     1.Mandatory parameters are left unspecified;
1009     *     2.Incorrect parameter types;
1010     *     3.Parameter verification failed.
1011     * @syscap SystemCapability.Utils.Lang
1012     * @crossplatform
1013     * @atomicservice
1014     * @since 12
1015     */
1016    doWritev(chunks: string[] | Uint8Array[], callback: Function): void;
1017
1018    /**
1019     * The implementation logic of flushing chunks in the buffer in batches should not be actively called.
1020     * The call is controlled by Writable.write.
1021     *
1022     * @param { string[] | Uint8Array[] } chunks - Data to be written.
1023     * @param { StreamCb } callback - Callback after writing.
1024     * @syscap SystemCapability.Utils.Lang
1025     * @crossplatform
1026     * @atomicservice
1027     * @since 20
1028     * @arkts 1.2
1029     */
1030    doWritev(chunks: string[] | Uint8Array[], callback: StreamCb): void;
1031
1032    /**
1033     * Returns boolean indicating whether it is in ObjectMode.
1034     *
1035     * @type { boolean }
1036     * @readonly
1037     * @syscap SystemCapability.Utils.Lang
1038     * @crossplatform
1039     * @atomicservice
1040     * @since arkts {'1.1':'12', '1.2':'20'}
1041     * @arkts 1.1&1.2
1042     */
1043    readonly writableObjectMode: boolean;
1044    /**
1045     * Value of highWatermark.
1046     *
1047     * @type { number }
1048     * @readonly
1049     * @syscap SystemCapability.Utils.Lang
1050     * @crossplatform
1051     * @atomicservice
1052     * @since arkts {'1.1':'12', '1.2':'20'}
1053     * @arkts 1.1&1.2
1054     */
1055    readonly writableHighWatermark: number;
1056    /**
1057     * Is true if it is safe to call writable.write(), which means the stream has not been destroyed, error or end.
1058     *
1059     * @type { boolean }
1060     * @readonly
1061     * @syscap SystemCapability.Utils.Lang
1062     * @crossplatform
1063     * @atomicservice
1064     * @since arkts {'1.1':'12', '1.2':'20'}
1065     * @arkts 1.1&1.2
1066     */
1067    readonly writable: boolean;
1068    /**
1069     * Size of data that can be flushed, in bytes or objects.
1070     *
1071     * @type { number }
1072     * @readonly
1073     * @syscap SystemCapability.Utils.Lang
1074     * @crossplatform
1075     * @atomicservice
1076     * @since arkts {'1.1':'12', '1.2':'20'}
1077     * @arkts 1.1&1.2
1078     */
1079    readonly writableLength: number;
1080    /**
1081     * Number of times writable.uncork() needs to be called in order to fully uncork the stream.
1082     *
1083     * @type { number }
1084     * @readonly
1085     * @syscap SystemCapability.Utils.Lang
1086     * @crossplatform
1087     * @atomicservice
1088     * @since arkts {'1.1':'12', '1.2':'20'}
1089     * @arkts 1.1&1.2
1090     */
1091    readonly writableCorked: number;
1092    /**
1093     * Whether Writable.end has been called.
1094     *
1095     * @type { boolean }
1096     * @readonly
1097     * @syscap SystemCapability.Utils.Lang
1098     * @crossplatform
1099     * @atomicservice
1100     * @since arkts {'1.1':'12', '1.2':'20'}
1101     * @arkts 1.1&1.2
1102     */
1103    readonly writableEnded: boolean;
1104    /**
1105     * Whether Writable.end has been called and all buffers have been flushed.
1106     *
1107     * @type { boolean }
1108     * @readonly
1109     * @syscap SystemCapability.Utils.Lang
1110     * @crossplatform
1111     * @atomicservice
1112     * @since arkts {'1.1':'12', '1.2':'20'}
1113     * @arkts 1.1&1.2
1114     */
1115    readonly writableFinished: boolean;
1116  }
1117}
1118export default stream;
1119