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 12 35 */ 36declare namespace stream { 37 /** 38 * Streams to which data can be written. 39 * 40 * @syscap SystemCapability.Utils.Lang 41 * @crossplatform 42 * @atomicservice 43 * @since 12 44 */ 45 class Writable { 46 /** 47 * The Writable constructor. 48 * 49 * @syscap SystemCapability.Utils.Lang 50 * @crossplatform 51 * @atomicservice 52 * @since 12 53 */ 54 constructor(); 55 /** 56 * writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates 57 * whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer 58 * does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function 59 * should be called after the drain event is triggered. If the write function is called continuously, 60 * the chunk is still added to the buffer until the memory overflows 61 * 62 * @param { string | Uint8Array } [chunk] - Data to be written. 63 * @param { string } [encoding] - Encoding type. 64 * @param { Function } [callback] - Callback after writing. 65 * @returns { boolean } Write success returns true, write failure returns false. 66 * @throws { BusinessError } 401 - Parameter error. Possible causes: 67 * 1.Mandatory parameters are left unspecified; 68 * 2.Incorrect parameter types; 69 * 3.Parameter verification failed. 70 * @throws { BusinessError } 10200035 - The doWrite method has not been implemented. 71 * @throws { BusinessError } 10200036 - The stream has been ended. 72 * @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively. 73 * @syscap SystemCapability.Utils.Lang 74 * @crossplatform 75 * @atomicservice 76 * @since 12 77 */ 78 write(chunk?: string | Uint8Array, encoding?: string, callback?: Function): boolean; 79 /** 80 * Write the last chunk to Writable. 81 * 82 * @param { string | Uint8Array } [chunk] - Data to be written. 83 * @param { string } [encoding] - Encoding type. 84 * @param { Function } [callback] - Callback after writing. 85 * @returns { Writable } Returns the Writable object. 86 * @throws { BusinessError } 401 - Parameter error. Possible causes: 87 * 1.Mandatory parameters are left unspecified; 88 * 2.Incorrect parameter types; 89 * 3.Parameter verification failed. 90 * @throws { BusinessError } 10200035 - The doWrite method has not been implemented. 91 * @syscap SystemCapability.Utils.Lang 92 * @crossplatform 93 * @atomicservice 94 * @since 12 95 */ 96 end(chunk?: string | Uint8Array, encoding?: string, callback?: Function): Writable; 97 /** 98 * Set the default encoding mode. 99 * 100 * @param { string } [encoding] - Encoding type.Default: utf8. 101 * @returns { boolean } Setting successful returns true, setting failed returns false. 102 * @throws { BusinessError } 401 - Parameter error. Possible causes: 103 * 1.Mandatory parameters are left unspecified; 104 * 2.Incorrect parameter types; 105 * 3.Parameter verification failed. 106 * @syscap SystemCapability.Utils.Lang 107 * @crossplatform 108 * @atomicservice 109 * @since 12 110 */ 111 setDefaultEncoding(encoding?: string): boolean; 112 /** 113 * After the call, all Write operations will be forced to write to the buffer instead of being flushed. 114 * 115 * @returns { boolean } Setting successful returns true, setting failed returns false. 116 * @syscap SystemCapability.Utils.Lang 117 * @crossplatform 118 * @atomicservice 119 * @since 12 120 */ 121 cork(): boolean; 122 /** 123 * After calling, flush all buffers. 124 * 125 * @returns { boolean } Setting successful returns true, setting failed returns false. 126 * @syscap SystemCapability.Utils.Lang 127 * @crossplatform 128 * @atomicservice 129 * @since 12 130 */ 131 uncork(): boolean; 132 /** 133 * Registering Event Messages. 134 * 135 * @param { string } event - Register Event. 136 * @param { Callback<emitter.EventData> } callback - event callbacks. 137 * @throws { BusinessError } 401 - Parameter error. Possible causes: 138 * 1.Mandatory parameters are left unspecified; 139 * 2.Incorrect parameter types; 140 * 3.Parameter verification failed. 141 * @syscap SystemCapability.Utils.Lang 142 * @crossplatform 143 * @atomicservice 144 * @since 12 145 */ 146 on(event: string, callback: Callback<emitter.EventData>): void; 147 /** 148 * Cancel event message. 149 * 150 * @param { string } event - Register Event. 151 * @param { Callback<emitter.EventData> } callback - event callbacks. 152 * @throws { BusinessError } 401 - Parameter error. Possible causes: 153 * 1.Mandatory parameters are left unspecified; 154 * 2.Incorrect parameter types. 155 * @syscap SystemCapability.Utils.Lang 156 * @crossplatform 157 * @atomicservice 158 * @since 12 159 */ 160 off(event: string, callback?: Callback<emitter.EventData>): void; 161 /** 162 * This method is invoked by the Writable method during initialization and must not be invoked directly. 163 * After the resource is initialized in the doInitialize method, the callback () method is invoked. 164 * 165 * @param { Function } callback - Callback when the stream has completed the initial. 166 * @throws { BusinessError } 401 - Parameter error. Possible causes: 167 * 1.Mandatory parameters are left unspecified; 168 * 2.Incorrect parameter types. 169 * @syscap SystemCapability.Utils.Lang 170 * @crossplatform 171 * @atomicservice 172 * @since 12 173 */ 174 doInitialize(callback: Function): void; 175 /** 176 * Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be 177 * directly called. The call is controlled by Writable.write. 178 * 179 * @param { string | Uint8Array } [chunk] - Data to be written. 180 * @param { string } [encoding] - Encoding type. 181 * @param { Function } [callback] - Callback after writing. 182 * @throws { BusinessError } 401 - Parameter error. Possible causes: 183 * 1.Mandatory parameters are left unspecified; 184 * 2.Incorrect parameter types; 185 * 3.Parameter verification failed. 186 * @syscap SystemCapability.Utils.Lang 187 * @crossplatform 188 * @atomicservice 189 * @since 12 190 */ 191 doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void; 192 /** 193 * The implementation logic of flushing chunks in the buffer in batches should not be actively called. 194 * The call is controlled by Writable.write. 195 * 196 * @param { string[] | Uint8Array[] } [chunks] - Data to be written. 197 * @param { Function } [callback] - Callback after writing. 198 * @throws { BusinessError } 401 - Parameter error. Possible causes: 199 * 1.Mandatory parameters are left unspecified; 200 * 2.Incorrect parameter types; 201 * 3.Parameter verification failed. 202 * @syscap SystemCapability.Utils.Lang 203 * @crossplatform 204 * @atomicservice 205 * @since 12 206 */ 207 doWritev(chunks: string[] | Uint8Array[], callback: Function): void; 208 /** 209 * Returns boolean indicating whether it is in ObjectMode. 210 * 211 * @type { boolean } 212 * @readonly 213 * @syscap SystemCapability.Utils.Lang 214 * @crossplatform 215 * @atomicservice 216 * @since 12 217 */ 218 readonly writableObjectMode: boolean; 219 /** 220 * Value of highWatermark. 221 * 222 * @type { number } 223 * @readonly 224 * @syscap SystemCapability.Utils.Lang 225 * @crossplatform 226 * @atomicservice 227 * @since 12 228 */ 229 readonly writableHighWatermark: number; 230 /** 231 * Is true if it is safe to call writable.write(), which means the stream has not been destroyed, error or end. 232 * 233 * @type { boolean } 234 * @readonly 235 * @syscap SystemCapability.Utils.Lang 236 * @crossplatform 237 * @atomicservice 238 * @since 12 239 */ 240 readonly writable: boolean; 241 /** 242 * Size of data that can be flushed, in bytes or objects. 243 * 244 * @type { number } 245 * @readonly 246 * @syscap SystemCapability.Utils.Lang 247 * @crossplatform 248 * @atomicservice 249 * @since 12 250 */ 251 readonly writableLength: number; 252 /** 253 * Number of times writable.uncork() needs to be called in order to fully uncork the stream. 254 * 255 * @type { number } 256 * @readonly 257 * @syscap SystemCapability.Utils.Lang 258 * @crossplatform 259 * @atomicservice 260 * @since 12 261 */ 262 readonly writableCorked: number; 263 /** 264 * Whether Writable.end has been called. 265 * 266 * @type { boolean } 267 * @readonly 268 * @syscap SystemCapability.Utils.Lang 269 * @crossplatform 270 * @atomicservice 271 * @since 12 272 */ 273 readonly writableEnded: boolean; 274 /** 275 * Whether Writable.end has been called and all buffers have been flushed. 276 * 277 * @type { boolean } 278 * @readonly 279 * @syscap SystemCapability.Utils.Lang 280 * @crossplatform 281 * @atomicservice 282 * @since 12 283 */ 284 readonly writableFinished: boolean; 285 } 286 /** 287 * Transform stream is a Duplex stream where the output is computed in some way from the input. 288 * Transform implementations must implement the doTransform() method and may also implement the doFlush() method. 289 * 290 * @extends Duplex 291 * @syscap SystemCapability.Utils.Lang 292 * @crossplatform 293 * @atomicservice 294 * @since 12 295 */ 296 class Transform extends Duplex { 297 /** 298 * The Transform constructor. 299 * 300 * @syscap SystemCapability.Utils.Lang 301 * @crossplatform 302 * @atomicservice 303 * @since 12 304 */ 305 constructor(); 306 /** 307 * Convert the input data. After the conversion, Transform.push can be called to send the input to the read stream. 308 * Transform.push should not be called Transform.write to call. 309 * 310 * @param { string } chunk - Input data to be converted. 311 * @param { string } encoding - If the chunk is a string, then this is the encoding type. If chunk is a buffer, 312 * then this is the special value 'buffer'. Ignore it in that case. 313 * @param { Function } callback - Callback after conversion. 314 * @throws { BusinessError } 401 - Parameter error. Possible causes: 315 * 1.Mandatory parameters are left unspecified; 316 * 2.Incorrect parameter types; 317 * 3.Parameter verification failed. 318 * @syscap SystemCapability.Utils.Lang 319 * @crossplatform 320 * @atomicservice 321 * @since 12 322 */ 323 doTransform(chunk: string, encoding: string, callback: Function): void; 324 /** 325 * After all data is flushed to the write stream, you can use the Transform.doFlush writes some extra data, must 326 * not be called directly, only called by Writable after flushing all data. 327 * 328 * @param { Function } callback - Callback after flush completion. 329 * @throws { BusinessError } 401 - Parameter error. Possible causes: 330 * 1.Mandatory parameters are left unspecified; 331 * 2.Incorrect parameter types; 332 * 3.Parameter verification failed. 333 * @syscap SystemCapability.Utils.Lang 334 * @crossplatform 335 * @atomicservice 336 * @since 12 337 */ 338 doFlush(callback: Function): void; 339 } 340 341 /** 342 * Return readable options. 343 * 344 * @interface ReadableOptions 345 * @syscap SystemCapability.Utils.Lang 346 * @crossplatform 347 * @atomicservice 348 * @since 12 349 */ 350 interface ReadableOptions { 351 /** 352 * Specifies the encoding format of the data. If this parameter is provided, 353 * the readable stream decodes the data into a string in the specified encoding format. Default: utf8. 354 * If an invalid string is entered, a 401 exception is thrown in the Readable constructor. 355 * Supported encoding formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6, 356 * 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, 357 * macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255, 358 * windows-1256, windows-1257, windows-1258, x-mac-cyrillic, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis, 359 * euc-kr, utf-16be, utf-16le. 360 * 361 * @type { ?string } 362 * @syscap SystemCapability.Utils.Lang 363 * @crossplatform 364 * @atomicservice 365 * @since 12 366 */ 367 encoding?: string; 368 } 369 370 /** 371 * The stream from which data can be read. 372 * 373 * @syscap SystemCapability.Utils.Lang 374 * @crossplatform 375 * @atomicservice 376 * @since 12 377 */ 378 class Readable { 379 /** 380 * The Readable constructor. 381 * 382 * @syscap SystemCapability.Utils.Lang 383 * @crossplatform 384 * @atomicservice 385 * @since 12 386 */ 387 constructor(); 388 /** 389 * The Readable constructor. 390 * 391 * @param { ReadableOptions } options - Provide options. 392 * @throws { BusinessError } 401 - Parameter error. Possible causes: 393 * 1.Mandatory parameters are left unspecified; 394 * 2.Incorrect parameter types; 395 * 3.Parameter verification failed. 396 * @syscap SystemCapability.Utils.Lang 397 * @crossplatform 398 * @atomicservice 399 * @since 12 400 */ 401 constructor(options: ReadableOptions); 402 /** 403 * Reads a buffer of a specified size from the buffer. If the available buffer is sufficient, the result 404 * of the specified size is returned. Otherwise, if Readable has ended, all remaining buffers are returned. 405 * 406 * @param { number } size - Expected length of the data to be read. 407 * @returns { string | null } If no data is available to read, null is returned. 408 * @throws { BusinessError } 401 - Parameter error. Possible causes: 409 * 1.Mandatory parameters are left unspecified; 410 * 2.Incorrect parameter types; 411 * 3.Parameter verification failed. 412 * @throws { BusinessError } 10200038 - The doRead method has not been implemented. 413 * @syscap SystemCapability.Utils.Lang 414 * @crossplatform 415 * @atomicservice 416 * @since 12 417 */ 418 read(size?: number): string | null; 419 /** 420 * Switch Readable to Streaming Mode. 421 * 422 * @returns { Readable } Return this object. 423 * @syscap SystemCapability.Utils.Lang 424 * @crossplatform 425 * @atomicservice 426 * @since 12 427 */ 428 resume(): Readable; 429 /** 430 * Toggle Readable to Suspend Mode. 431 * 432 * @returns { Readable } Return this object. 433 * @syscap SystemCapability.Utils.Lang 434 * @crossplatform 435 * @atomicservice 436 * @since 12 437 */ 438 pause(): Readable; 439 /** 440 * Sets the encoding format of the input binary data.Default: utf8. 441 * 442 * @param { string } [encoding] - Original Data Encoding Type. 443 * @returns { boolean } Setting successful returns true, setting failed returns false. 444 * @throws { BusinessError } 401 - Parameter error. Possible causes: 445 * 1.Mandatory parameters are left unspecified; 446 * 2.Incorrect parameter types. 447 * @syscap SystemCapability.Utils.Lang 448 * @crossplatform 449 * @atomicservice 450 * @since 12 451 */ 452 setEncoding(encoding?: string): boolean; 453 /** 454 * Query whether it is in pause state. 455 * 456 * @returns { boolean } Pause state returns true, otherwise returns false. 457 * @syscap SystemCapability.Utils.Lang 458 * @crossplatform 459 * @atomicservice 460 * @since 12 461 */ 462 isPaused(): boolean; 463 /** 464 * Concatenated a Writable to a Readable and switches the Readable to stream mode. 465 * 466 * @param { Writable } destination - Output writable stream. 467 * @param { Object } [options] - Pipeline Options. 468 * @returns { Writable } Returns the Writable object. 469 * @throws { BusinessError } 401 - Parameter error. Possible causes: 470 * 1.Mandatory parameters are left unspecified; 471 * 2.Incorrect parameter types; 472 * 3.Parameter verification failed. 473 * @syscap SystemCapability.Utils.Lang 474 * @crossplatform 475 * @atomicservice 476 * @since 12 477 */ 478 pipe(destination: Writable, options?: Object): Writable; 479 /** 480 * Disconnect Writable from Readable. 481 * 482 * @param { Writable } [destination] - Writable Streams Needing to Be Disconnected. 483 * @returns { Readable } Returns the Readable object. 484 * @throws { BusinessError } 401 - Parameter error. Possible causes: 485 * 1.Mandatory parameters are left unspecified; 486 * 2.Incorrect parameter types; 487 * 3.Parameter verification failed. 488 * @syscap SystemCapability.Utils.Lang 489 * @crossplatform 490 * @atomicservice 491 * @since 12 492 */ 493 unpipe(destination?: Writable): Readable; 494 /** 495 * Registering Event Messages. 496 * 497 * @param { string } event - Registering Events. 498 * @param { Callback<emitter.EventData> } callback - Event callback. 499 * @throws { BusinessError } 401 - Parameter error. Possible causes: 500 * 1.Mandatory parameters are left unspecified; 501 * 2.Incorrect parameter types. 502 * @syscap SystemCapability.Utils.Lang 503 * @crossplatform 504 * @atomicservice 505 * @since 12 506 */ 507 on(event: string, callback: Callback<emitter.EventData>): void; 508 /** 509 * Cancel event message. 510 * 511 * @param { string } event - Registering Events. 512 * @param { Callback<emitter.EventData> } callback - Event callback. 513 * @throws { BusinessError } 401 - Parameter error. Possible causes: 514 * 1.Mandatory parameters are left unspecified; 515 * 2.Incorrect parameter types. 516 * @syscap SystemCapability.Utils.Lang 517 * @crossplatform 518 * @atomicservice 519 * @since 12 520 */ 521 off(event: string, callback?: Callback<emitter.EventData>): void; 522 /** 523 * It may be implemented by child classes, and if so, will be called by the Readable class methods only. 524 * It must not be called directly. 525 * 526 * @param { Function } callback - Callback when the stream has completed the initial. 527 * @throws { BusinessError } 401 - Parameter error. Possible causes: 528 * 1.Mandatory parameters are left unspecified; 529 * 2.Incorrect parameter types; 530 * 3.Parameter verification failed. 531 * @syscap SystemCapability.Utils.Lang 532 * @crossplatform 533 * @atomicservice 534 * @since 12 535 */ 536 doInitialize(callback: Function): void; 537 /** 538 * The specific implementation of data production. It must not be actively called. 539 * After data production, Readable.push should be called to push the produced data into the buffer. 540 * If push is not called, doRead will not be called again. 541 * 542 * @param { number } size - Expected length of the data to be read. 543 * @throws { BusinessError } 401 - Parameter error. Possible causes: 544 * 1.Mandatory parameters are left unspecified; 545 * 2.Incorrect parameter types; 546 * 3.Parameter verification failed. 547 * @syscap SystemCapability.Utils.Lang 548 * @crossplatform 549 * @atomicservice 550 * @since 12 551 */ 552 doRead(size: number): void; 553 /** 554 * Adds the generated data to the buffer. The return value indicates whether the data in the buffer has not 555 * reached the highWaterMark (similar to Writable.write). If the chunk is null, all data has been generated. 556 * 557 * @param { Uint8Array | string | null } chunk - Binary data to be stored in the buffer. 558 * @param { string } [encoding] - Binary data encoding type. 559 * @returns { boolean } If true is returned, the data in the buffer reaches the highWaterMark. Otherwise, the 560 * data in the buffer does not reach the highWaterMark. 561 * @throws { BusinessError } 401 - Parameter error. Possible causes: 562 * 1.Mandatory parameters are left unspecified; 563 * 2.Incorrect parameter types. 564 * @syscap SystemCapability.Utils.Lang 565 * @crossplatform 566 * @atomicservice 567 * @since 12 568 */ 569 push(chunk: Uint8Array | string | null, encoding?: string): boolean; 570 /** 571 * Returns boolean indicating whether it is in ObjectMode. 572 * 573 * @type { boolean } 574 * @readonly 575 * @syscap SystemCapability.Utils.Lang 576 * @crossplatform 577 * @atomicservice 578 * @since 12 579 */ 580 readonly readableObjectMode: boolean; 581 /** 582 * Is true if it is safe to call readable.read(), which means 583 * the stream has not been destroyed or emitted 'error' or 'end'. 584 * 585 * @type { boolean } 586 * @readonly 587 * @syscap SystemCapability.Utils.Lang 588 * @crossplatform 589 * @atomicservice 590 * @since 12 591 */ 592 readonly readable: boolean; 593 /** 594 * Returns the value of highWatermark passed when creating this Readable. 595 * 596 * @type { number } 597 * @readonly 598 * @syscap SystemCapability.Utils.Lang 599 * @crossplatform 600 * @atomicservice 601 * @since 12 602 */ 603 readonly readableHighWatermark: number; 604 /** 605 * This property reflects the current state of the readable stream null/true/false. 606 * 607 * @type { boolean | null } 608 * @readonly 609 * @syscap SystemCapability.Utils.Lang 610 * @crossplatform 611 * @atomicservice 612 * @since 12 613 */ 614 readonly readableFlowing: boolean | null; 615 /** 616 * Size of the data that can be read, in bytes or objects. 617 * 618 * @type { number } 619 * @readonly 620 * @syscap SystemCapability.Utils.Lang 621 * @crossplatform 622 * @atomicservice 623 * @since 12 624 */ 625 readonly readableLength: number; 626 /** 627 * Getter for the property encoding of a given Readable stream. The encoding property can be set using the 628 * readable.setEncoding() method. 629 * 630 * @type { string | null } 631 * @readonly 632 * @syscap SystemCapability.Utils.Lang 633 * @crossplatform 634 * @atomicservice 635 * @since 12 636 */ 637 readonly readableEncoding: string | null; 638 /** 639 * Whether all data has been generated. 640 * 641 * @type { boolean } 642 * @readonly 643 * @syscap SystemCapability.Utils.Lang 644 * @crossplatform 645 * @atomicservice 646 * @since 12 647 */ 648 readonly readableEnded: boolean; 649 } 650 /** 651 * Duplex streams are streams that implement both the Readable streams and Writable streams interfaces. 652 * 653 * @extends Readable 654 * @syscap SystemCapability.Utils.Lang 655 * @crossplatform 656 * @atomicservice 657 * @since 12 658 */ 659 class Duplex extends Readable { 660 /** 661 * The Duplex constructor. 662 * 663 * @syscap SystemCapability.Utils.Lang 664 * @crossplatform 665 * @atomicservice 666 * @since 12 667 */ 668 constructor(); 669 /** 670 * writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates 671 * whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer 672 * does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function 673 * should be called after the drain event is triggered. If the write function is called continuously, 674 * the chunk is still added to the buffer until the memory overflows 675 * 676 * @param { string | Uint8Array } [chunk] - Data to be written. 677 * @param { string } [encoding] - Encoding type. 678 * @param { Function } [callback] - Callback after writing. 679 * @returns { boolean } Write success returns true, write failure returns false. 680 * @throws { BusinessError } 401 - Parameter error. Possible causes: 681 * 1.Mandatory parameters are left unspecified; 682 * 2.Incorrect parameter types; 683 * 3.Parameter verification failed. 684 * @throws { BusinessError } 10200036 - The stream has been ended. 685 * @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively. 686 * @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform. 687 * @syscap SystemCapability.Utils.Lang 688 * @crossplatform 689 * @atomicservice 690 * @since 12 691 */ 692 write(chunk?: string | Uint8Array, encoding?: string, callback?: Function): boolean; 693 /** 694 * Write the last chunk to Writable. 695 * 696 * @param { string | Uint8Array } [chunk] - Data to be written. 697 * @param { string } [encoding] - Encoding type. 698 * @param { Function } [callback] - Callback after writing. 699 * @returns { Writable } Returns the Writable object. 700 * @throws { BusinessError } 401 - Parameter error. Possible causes: 701 * 1.Mandatory parameters are left unspecified; 702 * 2.Incorrect parameter types; 703 * 3.Parameter verification failed. 704 * @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform. 705 * @syscap SystemCapability.Utils.Lang 706 * @crossplatform 707 * @atomicservice 708 * @since 12 709 */ 710 end(chunk?: string | Uint8Array, encoding?: string, callback?: Function): Writable; 711 /** 712 * Set the default encoding mode. 713 * 714 * @param { string } [encoding] - Encoding type.Default: utf8. 715 * @returns { boolean } Setting successful returns true, setting failed returns false. 716 * @throws { BusinessError } 401 - Parameter error. Possible causes: 717 * 1.Mandatory parameters are left unspecified; 718 * 2.Incorrect parameter types; 719 * 3.Parameter verification failed. 720 * @syscap SystemCapability.Utils.Lang 721 * @crossplatform 722 * @atomicservice 723 * @since 12 724 */ 725 setDefaultEncoding(encoding?: string): boolean; 726 /** 727 * After the call, all Write operations will be forced to write to the buffer instead of being flushed. 728 * 729 * @returns { boolean } Setting successful returns true, setting failed returns false. 730 * @syscap SystemCapability.Utils.Lang 731 * @crossplatform 732 * @atomicservice 733 * @since 12 734 */ 735 cork(): boolean; 736 /** 737 * After calling, flush all buffers. 738 * 739 * @returns { boolean } Setting successful returns true, setting failed returns false. 740 * @syscap SystemCapability.Utils.Lang 741 * @crossplatform 742 * @atomicservice 743 * @since 12 744 */ 745 uncork(): boolean; 746 /** 747 * Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be 748 * directly called. The call is controlled by Writable.write. 749 * 750 * @param { string | Uint8Array } [chunk] - Data to be written. 751 * @param { string } [encoding] - Encoding type. 752 * @param { Function } [callback] - Callback after writing. 753 * @throws { BusinessError } 401 - Parameter error. Possible causes: 754 * 1.Mandatory parameters are left unspecified; 755 * 2.Incorrect parameter types; 756 * 3.Parameter verification failed. 757 * @syscap SystemCapability.Utils.Lang 758 * @crossplatform 759 * @atomicservice 760 * @since 12 761 */ 762 doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void; 763 /** 764 * The implementation logic of flushing chunks in the buffer in batches should not be actively called. 765 * The call is controlled by Writable.write. 766 * 767 * @param { string[] | Uint8Array[] } [chunks] - Data to be written. 768 * @param { Function } [callback] - Callback after writing. 769 * @throws { BusinessError } 401 - Parameter error. Possible causes: 770 * 1.Mandatory parameters are left unspecified; 771 * 2.Incorrect parameter types; 772 * 3.Parameter verification failed. 773 * @syscap SystemCapability.Utils.Lang 774 * @crossplatform 775 * @atomicservice 776 * @since 12 777 */ 778 doWritev(chunks: string[] | Uint8Array[], callback: Function): void; 779 /** 780 * Returns boolean indicating whether it is in ObjectMode. 781 * 782 * @type { boolean } 783 * @readonly 784 * @syscap SystemCapability.Utils.Lang 785 * @crossplatform 786 * @atomicservice 787 * @since 12 788 */ 789 readonly writableObjectMode: boolean; 790 /** 791 * Value of highWatermark. 792 * 793 * @type { number } 794 * @readonly 795 * @syscap SystemCapability.Utils.Lang 796 * @crossplatform 797 * @atomicservice 798 * @since 12 799 */ 800 readonly writableHighWatermark: number; 801 /** 802 * Is true if it is safe to call writable.write(), which means the stream has not been destroyed, error or end. 803 * 804 * @type { boolean } 805 * @readonly 806 * @syscap SystemCapability.Utils.Lang 807 * @crossplatform 808 * @atomicservice 809 * @since 12 810 */ 811 readonly writable: boolean; 812 /** 813 * Size of data that can be flushed, in bytes or objects. 814 * 815 * @type { number } 816 * @readonly 817 * @syscap SystemCapability.Utils.Lang 818 * @crossplatform 819 * @atomicservice 820 * @since 12 821 */ 822 readonly writableLength: number; 823 /** 824 * Number of times writable.uncork() needs to be called in order to fully uncork the stream. 825 * 826 * @type { number } 827 * @readonly 828 * @syscap SystemCapability.Utils.Lang 829 * @crossplatform 830 * @atomicservice 831 * @since 12 832 */ 833 readonly writableCorked: number; 834 /** 835 * Whether Writable.end has been called. 836 * 837 * @type { boolean } 838 * @readonly 839 * @syscap SystemCapability.Utils.Lang 840 * @crossplatform 841 * @atomicservice 842 * @since 12 843 */ 844 readonly writableEnded: boolean; 845 /** 846 * Whether Writable.end has been called and all buffers have been flushed. 847 * 848 * @type { boolean } 849 * @readonly 850 * @syscap SystemCapability.Utils.Lang 851 * @crossplatform 852 * @atomicservice 853 * @since 12 854 */ 855 readonly writableFinished: boolean; 856 } 857} 858export default stream;