46 Star 173 Fork 4.7K

OpenHarmony/interface_sdk-js

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
@ohos.util.stream.d.ts 40.63 KB
Copy Edit Raw Blame History
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @kit ArkTS
*/
import { Callback } from './@ohos.base';
import emitter from './@ohos.events.emitter';
/**
* The stream module provides a comprehensive set of stream processing capabilities, including four types of streams:
* - Writable: streams designed for writing data to.
* - Readable: streams designed for reading data from.
* - Duplex: streams that are both readable and writable.
* - Transform: a specialized type of duplex stream that can modify or transform data as it's being written and read.
*
* @namespace stream
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
declare namespace stream {
/**
* The type of stream callback function.
*
* @typedef { function } StreamCb
* @returns { void } - The function return void
* @syscap SystemCapability.Utils.Lang
* @atomicservice
* @since 20
* @arkts 1.2
*/
type StreamCb = () => void;
/**
* Streams to which data can be written.
*
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
class Writable {
/**
* The Writable constructor.
*
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
constructor();
/**
* writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
* whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
* does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
* should be called after the drain event is triggered. If the write function is called continuously,
* the chunk is still added to the buffer until the memory overflows
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { Function } [callback] - Callback after writing.
* @returns { boolean } Write success returns true, write failure returns false.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
* @throws { BusinessError } 10200036 - The stream has been ended.
* @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
write(chunk?: string | Uint8Array, encoding?: string, callback?: Function): boolean;
/**
* writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
* whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
* does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
* should be called after the drain event is triggered. If the write function is called continuously,
* the chunk is still added to the buffer until the memory overflows
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { StreamCb } [callback] - Callback after writing.
* @returns { boolean } Write success returns true, write failure returns false.
* @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
* @throws { BusinessError } 10200036 - The stream has been ended.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
write(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): boolean;
/**
* Write the last chunk to Writable.
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { Function } [callback] - Callback after writing.
* @returns { Writable } Returns the Writable object.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
end(chunk?: string | Uint8Array, encoding?: string, callback?: Function): Writable;
/**
* Write the last chunk to Writable.
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { StreamCb } [callback] - Callback after writing.
* @returns { Writable } Returns the Writable object.
* @throws { BusinessError } 10200035 - The doWrite method has not been implemented.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
end(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): Writable;
/**
* Set the default encoding mode.
*
* @param { string } [encoding] - Encoding type.Default: utf8.
* @returns { boolean } Setting successful returns true, setting failed returns false.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
setDefaultEncoding(encoding?: string): boolean;
/**
* After the call, all Write operations will be forced to write to the buffer instead of being flushed.
*
* @returns { boolean } Setting successful returns true, setting failed returns false.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
cork(): boolean;
/**
* After calling, flush all buffers.
*
* @returns { boolean } Setting successful returns true, setting failed returns false.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
uncork(): boolean;
/**
* Registering Event Messages.
*
* @param { string } event - Register Event.
* @param { Callback<emitter.EventData> } callback - event callbacks.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
on(event: string, callback: Callback<emitter.EventData>): void;
/**
* Cancel event message.
*
* @param { string } event - Register Event.
* @param { Callback<emitter.EventData> } callback - event callbacks.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
off(event: string, callback?: Callback<emitter.EventData>): void;
/**
* This method is invoked by the Writable method during initialization and must not be invoked directly.
* After the resource is initialized in the doInitialize method, the callback () method is invoked.
*
* @param { Function } callback - Callback when the stream has completed the initial.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doInitialize(callback: Function): void;
/**
* This method is invoked by the Writable method during initialization and must not be invoked directly.
* After the resource is initialized in the doInitialize method, the callback () method is invoked.
*
* @param { StreamCb } callback - Callback when the stream has completed the initial.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doInitialize(callback: StreamCb): void;
/**
* Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
* directly called. The call is controlled by Writable.write.
*
* @param { string | Uint8Array } chunk - Data to be written.
* @param { string } encoding - Encoding type.
* @param { Function } callback - Callback after writing.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void;
/**
* Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
* directly called. The call is controlled by Writable.write.
*
* @param { string | Uint8Array } chunk - Data to be written.
* @param { string } encoding - Encoding type.
* @param { StreamCb } callback - Callback after writing.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doWrite(chunk: string | Uint8Array, encoding: string, callback: StreamCb): void;
/**
* The implementation logic of flushing chunks in the buffer in batches should not be actively called.
* The call is controlled by Writable.write.
*
* @param { string[] | Uint8Array[] } chunks - Data to be written.
* @param { Function } callback - Callback after writing.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doWritev(chunks: string[] | Uint8Array[], callback: Function): void;
/**
* The implementation logic of flushing chunks in the buffer in batches should not be actively called.
* The call is controlled by Writable.write.
*
* @param { string[] | Uint8Array[] } chunks - Data to be written.
* @param { StreamCb } callback - Callback after writing.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doWritev(chunks: string[] | Uint8Array[], callback: StreamCb): void;
/**
* Returns boolean indicating whether it is in ObjectMode.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableObjectMode: boolean;
/**
* Value of highWatermark.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableHighWatermark: number;
/**
* Is true if it is safe to call writable.write(), which means the stream has not been destroyed, error or end.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writable: boolean;
/**
* Size of data that can be flushed, in bytes or objects.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableLength: number;
/**
* Number of times writable.uncork() needs to be called in order to fully uncork the stream.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableCorked: number;
/**
* Whether Writable.end has been called.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableEnded: boolean;
/**
* Whether Writable.end has been called and all buffers have been flushed.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableFinished: boolean;
}
/**
* Transform stream is a Duplex stream where the output is computed in some way from the input.
* Transform implementations must implement the doTransform() method and may also implement the doFlush() method.
*
* @extends Duplex
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
class Transform extends Duplex {
/**
* The Transform constructor.
*
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
constructor();
/**
* Convert the input data. After the conversion, Transform.push can be called to send the input to the read stream.
* Transform.push should not be called Transform.write to call.
*
* @param { string } chunk - Input data to be converted.
* @param { string } encoding - If the chunk is a string, then this is the encoding type. If chunk is a buffer,
* then this is the special value 'buffer'. Ignore it in that case.
* @param { Function } callback - Callback after conversion.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doTransform(chunk: string, encoding: string, callback: Function): void;
/**
* Convert the input data. After the conversion, Transform.push can be called to send the input to the read stream.
* Transform.push should not be called Transform.write to call.
*
* @param { string } chunk - Input data to be converted.
* @param { string } encoding - If the chunk is a string, then this is the encoding type. If chunk is a buffer,
* then this is the special value 'buffer'. Ignore it in that case.
* @param { StreamCb } callback - Callback after conversion.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doTransform(chunk: string, encoding: string, callback: StreamCb): void;
/**
* After all data is flushed to the write stream, you can use the Transform.doFlush writes some extra data, must
* not be called directly, only called by Writable after flushing all data.
*
* @param { Function } callback - Callback after flush completion.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doFlush(callback: Function): void;
/**
* After all data is flushed to the write stream, you can use the Transform.doFlush writes some extra data, must
* not be called directly, only called by Writable after flushing all data.
*
* @param { StreamCb } callback - Callback after flush completion.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doFlush(callback: StreamCb): void;
}
/**
* Return readable options.
*
* @interface ReadableOptions
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
interface ReadableOptions {
/**
* Specifies the encoding format of the data. If this parameter is provided,
* the readable stream decodes the data into a string in the specified encoding format. Default: utf8.
* If an invalid string is entered, a 401 exception is thrown in the Readable constructor.
* Supported encoding formats: utf-8, ibm866, iso-8859-2, iso-8859-3, iso-8859-4, iso-8859-5, iso-8859-6,
* 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,
* macintosh, windows-874, windows-1250, windows-1251, windows-1252, windows-1253, windows-1254, windows-1255,
* windows-1256, windows-1257, windows-1258, x-mac-cyrillic, gbk, gb18030, big5, euc-jp, iso-2022-jp, shift_jis,
* euc-kr, utf-16be, utf-16le.
*
* @type { ?string }
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
encoding?: string;
}
/**
* The stream from which data can be read.
*
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
class Readable {
/**
* The Readable constructor.
*
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
constructor();
/**
* The Readable constructor.
*
* @param { ReadableOptions } options - Provide options.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
constructor(options: ReadableOptions);
/**
* Reads a buffer of a specified size from the buffer. If the available buffer is sufficient, the result
* of the specified size is returned. Otherwise, if Readable has ended, all remaining buffers are returned.
*
* @param { number } size - Expected length of the data to be read.
* @returns { string | null } If no data is available to read, null is returned.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @throws { BusinessError } 10200038 - The doRead method has not been implemented.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
read(size?: number): string | null;
/**
* Switch Readable to Streaming Mode.
*
* @returns { Readable } Return this object.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
resume(): Readable;
/**
* Toggle Readable to Suspend Mode.
*
* @returns { Readable } Return this object.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
pause(): Readable;
/**
* Sets the encoding format of the input binary data.Default: utf8.
*
* @param { string } [encoding] - Original Data Encoding Type.
* @returns { boolean } Setting successful returns true, setting failed returns false.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
setEncoding(encoding?: string): boolean;
/**
* Query whether it is in pause state.
*
* @returns { boolean } Pause state returns true, otherwise returns false.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
isPaused(): boolean;
/**
* Concatenated a Writable to a Readable and switches the Readable to stream mode.
*
* @param { Writable } destination - Output writable stream.
* @param { Object } [options] - Pipeline Options.
* @returns { Writable } Returns the Writable object.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
pipe(destination: Writable, options?: Object): Writable;
/**
* Disconnect Writable from Readable.
*
* @param { Writable } [destination] - Writable Streams Needing to Be Disconnected.
* @returns { Readable } Returns the Readable object.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
unpipe(destination?: Writable): Readable;
/**
* Registering Event Messages.
*
* @param { string } event - Registering Events.
* @param { Callback<emitter.EventData> } callback - Event callback.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
on(event: string, callback: Callback<emitter.EventData>): void;
/**
* Cancel event message.
*
* @param { string } event - Registering Events.
* @param { Callback<emitter.EventData> } callback - Event callback.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
off(event: string, callback?: Callback<emitter.EventData>): void;
/**
* It may be implemented by child classes, and if so, will be called by the Readable class methods only.
* It must not be called directly.
*
* @param { Function } callback - Callback when the stream has completed the initial.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doInitialize(callback: Function): void;
/**
* It may be implemented by child classes, and if so, will be called by the Readable class methods only.
* It must not be called directly.
*
* @param { StreamCb } callback - Callback when the stream has completed the initial.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doInitialize(callback: StreamCb): void;
/**
* The specific implementation of data production. It must not be actively called.
* After data production, Readable.push should be called to push the produced data into the buffer.
* If push is not called, doRead will not be called again.
*
* @param { number } size - Expected length of the data to be read.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
doRead(size: number): void;
/**
* Adds the generated data to the buffer. The return value indicates whether the data in the buffer has not
* reached the highWaterMark (similar to Writable.write). If the chunk is null, all data has been generated.
*
* @param { Uint8Array | string | null } chunk - Binary data to be stored in the buffer.
* @param { string } [encoding] - Binary data encoding type.
* @returns { boolean } If true is returned, the data in the buffer reaches the highWaterMark. Otherwise, the
* data in the buffer does not reach the highWaterMark.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
push(chunk: Uint8Array | string | null, encoding?: string): boolean;
/**
* Returns boolean indicating whether it is in ObjectMode.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly readableObjectMode: boolean;
/**
* Is true if it is safe to call readable.read(), which means
* the stream has not been destroyed or emitted 'error' or 'end'.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly readable: boolean;
/**
* Returns the value of highWatermark passed when creating this Readable.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly readableHighWatermark: number;
/**
* This property reflects the current state of the readable stream null/true/false.
*
* @type { boolean | null }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly readableFlowing: boolean | null;
/**
* Size of the data that can be read, in bytes or objects.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly readableLength: number;
/**
* Getter for the property encoding of a given Readable stream. The encoding property can be set using the
* readable.setEncoding() method.
*
* @type { string | null }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly readableEncoding: string | null;
/**
* Whether all data has been generated.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly readableEnded: boolean;
}
/**
* Duplex streams are streams that implement both the Readable streams and Writable streams interfaces.
*
* @extends Readable
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
class Duplex extends Readable {
/**
* The Duplex constructor.
*
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
constructor();
/**
* writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
* whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
* does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
* should be called after the drain event is triggered. If the write function is called continuously,
* the chunk is still added to the buffer until the memory overflows
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { Function } [callback] - Callback after writing.
* @returns { boolean } Write success returns true, write failure returns false.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @throws { BusinessError } 10200036 - The stream has been ended.
* @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively.
* @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
write(chunk?: string | Uint8Array, encoding?: string, callback?: Function): boolean;
/**
* writes a chunk to Writable and invokes callback when the chunk is flushed. The return value indicates
* whether the internal buffer of the Writable reaches the hightWaterMark. If true is returned, the buffer
* does not reach the hightWaterMark. If false is returned, the buffer has been reached. The write function
* should be called after the drain event is triggered. If the write function is called continuously,
* the chunk is still added to the buffer until the memory overflows
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { StreamCb } [callback] - Callback after writing.
* @returns { boolean } Write success returns true, write failure returns false.
* @throws { BusinessError } 10200036 - The stream has been ended.
* @throws { BusinessError } 10200037 - The callback is invoked multiple times consecutively.
* @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
write(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): boolean;
/**
* Write the last chunk to Writable.
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { Function } [callback] - Callback after writing.
* @returns { Writable } Returns the Writable object.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
end(chunk?: string | Uint8Array, encoding?: string, callback?: Function): Writable;
/**
* Write the last chunk to Writable.
*
* @param { string | Uint8Array } [chunk] - Data to be written.
* @param { string } [encoding] - Encoding type.
* @param { StreamCb } [callback] - Callback after writing.
* @returns { Writable } Returns the Writable object.
* @throws { BusinessError } 10200039 - The doTransform method has not been implemented for a class that inherits from Transform.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
end(chunk?: string | Uint8Array, encoding?: string, callback?: StreamCb): Writable;
/**
* Set the default encoding mode.
*
* @param { string } [encoding] - Encoding type.Default: utf8.
* @returns { boolean } Setting successful returns true, setting failed returns false.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
setDefaultEncoding(encoding?: string): boolean;
/**
* After the call, all Write operations will be forced to write to the buffer instead of being flushed.
*
* @returns { boolean } Setting successful returns true, setting failed returns false.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
cork(): boolean;
/**
* After calling, flush all buffers.
*
* @returns { boolean } Setting successful returns true, setting failed returns false.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
uncork(): boolean;
/**
* Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
* directly called. The call is controlled by Writable.write.
*
* @param { string | Uint8Array } chunk - Data to be written.
* @param { string } encoding - Encoding type.
* @param { Function } callback - Callback after writing.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void;
/**
* Implemented by subclass inheritance. The implementation logic of flushing chunks in the buffer must not be
* directly called. The call is controlled by Writable.write.
*
* @param { string | Uint8Array } chunk - Data to be written.
* @param { string } encoding - Encoding type.
* @param { StreamCb } callback - Callback after writing.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doWrite(chunk: string | Uint8Array, encoding: string, callback: StreamCb): void;
/**
* The implementation logic of flushing chunks in the buffer in batches should not be actively called.
* The call is controlled by Writable.write.
*
* @param { string[] | Uint8Array[] } chunks - Data to be written.
* @param { Function } callback - Callback after writing.
* @throws { BusinessError } 401 - Parameter error. Possible causes:
* 1.Mandatory parameters are left unspecified;
* 2.Incorrect parameter types;
* 3.Parameter verification failed.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 12
*/
doWritev(chunks: string[] | Uint8Array[], callback: Function): void;
/**
* The implementation logic of flushing chunks in the buffer in batches should not be actively called.
* The call is controlled by Writable.write.
*
* @param { string[] | Uint8Array[] } chunks - Data to be written.
* @param { StreamCb } callback - Callback after writing.
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since 20
* @arkts 1.2
*/
doWritev(chunks: string[] | Uint8Array[], callback: StreamCb): void;
/**
* Returns boolean indicating whether it is in ObjectMode.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableObjectMode: boolean;
/**
* Value of highWatermark.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableHighWatermark: number;
/**
* Is true if it is safe to call writable.write(), which means the stream has not been destroyed, error or end.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writable: boolean;
/**
* Size of data that can be flushed, in bytes or objects.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableLength: number;
/**
* Number of times writable.uncork() needs to be called in order to fully uncork the stream.
*
* @type { number }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableCorked: number;
/**
* Whether Writable.end has been called.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableEnded: boolean;
/**
* Whether Writable.end has been called and all buffers have been flushed.
*
* @type { boolean }
* @readonly
* @syscap SystemCapability.Utils.Lang
* @crossplatform
* @atomicservice
* @since arkts {'1.1':'12', '1.2':'20'}
* @arkts 1.1&1.2
*/
readonly writableFinished: boolean;
}
}
export default stream;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/interface_sdk-js.git
git@gitee.com:openharmony/interface_sdk-js.git
openharmony
interface_sdk-js
interface_sdk-js
master

Search