1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (The type of "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 * The Buffer class is a global type for dealing with binary data directly. It can be constructed in a variety of ways. 17 * @since 18 * @syscap SystemCapability.Utils.Lang 19 * @permission N/A 20 */ 21declare namespace buffer { 22 23 type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex'; 24 25 interface TypedArray extends Int8Array {} 26 /** 27 * Allocates a new Buffer for a fixed size bytes. If fill is undefined, the Buffer will be zero-filled. 28 * @since 9 29 * @syscap SystemCapability.Utils.Lang 30 * @param size The desired length of the new Buffer 31 * @param [fill=0] A value to pre-fill the new Buffer with 32 * @param [encoding='utf8'] If `fill` is a string, this is its encoding 33 * @returns Return a new allocated Buffer 34 * @throws {BusinessError} 401 - if the input parameters are invalid. 35 */ 36 function alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer; 37 38 /** 39 * Allocates a new Buffer for a fixed size bytes. The Buffer will not be initially filled. 40 * @since 9 41 * @syscap SystemCapability.Utils.Lang 42 * @param size The desired length of the new Buffer 43 * @returns Return a new allocated Buffer 44 * @throws {BusinessError} 401 - if the input parameters are invalid. 45 */ 46 function allocUninitializedFromPool(size: number): Buffer; 47 48 /** 49 * Allocates a new un-pooled Buffer for a fixed size bytes. The Buffer will not be initially filled. 50 * @since 9 51 * @syscap SystemCapability.Utils.Lang 52 * @param size The desired length of the new Buffer 53 * @returns Return a new allocated Buffer 54 * @throws {BusinessError} 401 - if the input parameters are invalid. 55 */ 56 function allocUninitialized(size: number): Buffer; 57 58 /** 59 * Returns the byte length of a string when encoded using `encoding`. 60 * This is not the same as [`String.prototype.length`], which does not account 61 * for the encoding that is used to convert the string into bytes. 62 * @since 9 63 * @syscap SystemCapability.Utils.Lang 64 * @param string A value to calculate the length of 65 * @param [encoding='utf8'] If `string` is a string, this is its encoding 66 * @returns The number of bytes contained within `string` 67 * @throws {BusinessError} 401 - if the input parameters are invalid. 68 */ 69 function byteLength(string: string | Buffer | TypedArray | DataView | ArrayBuffer | SharedArrayBuffer, encoding?: BufferEncoding): number; 70 71 /** 72 * Returns a new `Buffer` which is the result of concatenating all the `Buffer`instances in the `list` together. 73 * @since 9 74 * @syscap SystemCapability.Utils.Lang 75 * @param list List of `Buffer` or Uint8Array instances to concatenate 76 * @param totalLength Total length of the `Buffer` instances in `list` when concatenated 77 * @returns Return a new allocated Buffer 78 * @throws {BusinessError} 401 - if the input parameters are invalid. 79 * @throws {BusinessError} 10200001 - The value of "length" is out of range. It must be >= 0 and <= uint32 max. Received value is: [length] 80 */ 81 function concat(list: Buffer[] | Uint8Array[], totalLength?: number): Buffer; 82 83 /** 84 * Allocates a new Buffer using an array of bytes in the range 0 – 255. Array entries outside that range will be truncated to fit into it. 85 * @since 9 86 * @syscap SystemCapability.Utils.Lang 87 * @param array an array of bytes in the range 0 – 255 88 * @returns Return a new allocated Buffer 89 * @throws {BusinessError} 401 - if the input parameters are invalid. 90 */ 91 function from(array: number[]): Buffer; 92 93 /** 94 * This creates a view of the ArrayBuffer without copying the underlying memory. 95 * @since 9 96 * @syscap SystemCapability.Utils.Lang 97 * @param arrayBuffer An ArrayBuffer, SharedArrayBuffer, for example the .buffer property of a TypedArray. 98 * @param [byteOffset = 0] Index of first byte to expose 99 * @param [length = arrayBuffer.byteLength - byteOffset] Number of bytes to expose 100 * @returns Return a view of the ArrayBuffer 101 * @throws {BusinessError} 401 - if the input parameters are invalid. 102 * @throws {BusinessError} 10200001 - The value of "[byteOffset/length]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [byteOffset/length] 103 */ 104 function from(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer; 105 106 /** 107 * Copies the passed buffer data onto a new Buffer instance. 108 * @since 9 109 * @syscap SystemCapability.Utils.Lang 110 * @param buffer An existing Buffer or Uint8Array from which to copy data 111 * @returns Return a new allocated Buffer 112 * @throws {BusinessError} 401 - if the input parameters are invalid. 113 */ 114 function from(buffer: Buffer | Uint8Array): Buffer; 115 116 /** 117 * For the object whose value returned by valueof() function is strictly equal to object 118 * or supports symbol To primitive object, a new buffer instance is created. 119 * @since 9 120 * @syscap SystemCapability.Utils.Lang 121 * @param object An object supporting Symbol.toPrimitive or valueOf() 122 * @param offsetOrEncoding A byte-offset or encoding 123 * @param length A length 124 * @returns Return a new allocated Buffer 125 * @throws {BusinessError} 401 - if the input parameters are invalid. 126 */ 127 function from(object: Object, offsetOrEncoding: number | string, length: number): Buffer; 128 129 /** 130 * Creates a new Buffer containing string. The encoding parameter identifies the character encoding 131 * to be used when converting string into bytes. 132 * @since 9 133 * @syscap SystemCapability.Utils.Lang 134 * @param string A string to encode 135 * @param [encoding='utf8'] The encoding of string 136 * @returns Return a new Buffer containing string 137 * @throws {BusinessError} 401 - if the input parameters are invalid. 138 */ 139 function from(string: String, encoding?: BufferEncoding): Buffer; 140 141 /** 142 * Returns true if obj is a Buffer, false otherwise 143 * @since 9 144 * @syscap SystemCapability.Utils.Lang 145 * @param obj Objects to be judged 146 * @returns true or false 147 */ 148 function isBuffer(obj: Object): boolean; 149 150 /** 151 * Returns true if encoding is the name of a supported character encoding, or false otherwise. 152 * @since 9 153 * @syscap SystemCapability.Utils.Lang 154 * @param encoding A character encoding name to check 155 * @returns true or false 156 */ 157 function isEncoding(encoding: string):boolean; 158 159 /** 160 * Compares buf1 to buf2 161 * @since 9 162 * @syscap SystemCapability.Utils.Lang 163 * @param buf1 A Buffer or Uint8Array instance. 164 * @param buf2 A Buffer or Uint8Array instance. 165 * @returns 0 is returned if target is the same as buf 166 * 1 is returned if target should come before buf when sorted. 167 * -1 is returned if target should come after buf when sorted. 168 * @throws {BusinessError} 401 - if the input parameters are invalid. 169 */ 170 function compare(buf1: Buffer | Uint8Array, buf2: Buffer | Uint8Array): -1 | 0 | 1; 171 172 /** 173 * Re-encodes the given Buffer or Uint8Array instance from one character encoding to another. 174 * @since 9 175 * @syscap SystemCapability.Utils.Lang 176 * @param source A Buffer or Uint8Array instance. 177 * @param fromEnc The current encoding 178 * @param toEnc To target encoding 179 * @returns Returns a new Buffer instance 180 * @throws {BusinessError} 401 - if the input parameters are invalid. 181 */ 182 function transcode(source: Buffer | Uint8Array, fromEnc: string, toEnc: string): Buffer; 183 184 185 186 class Buffer { 187 188 /** 189 * Returns the number of bytes in buf 190 * @since 9 191 * @syscap SystemCapability.Utils.Lang 192 * @throws {BusinessError} 10200013 - Cannot set property length of Buffer which has only a getter 193 */ 194 length: number; 195 196 /** 197 * The underlying ArrayBuffer object based on which this Buffer object is created. 198 * @since 9 199 * @syscap SystemCapability.Utils.Lang 200 * @throws {BusinessError} 10200013 - Cannot set property buffer of Buffer which has only a getter 201 */ 202 buffer: ArrayBuffer; 203 204 /** 205 * The byteOffset of the Buffers underlying ArrayBuffer object 206 * @since 9 207 * @syscap SystemCapability.Utils.Lang 208 * @throws {BusinessError} 10200013 - Cannot set property byteOffset of Buffer which has only a getter 209 */ 210 byteOffset: number; 211 212 /** 213 * Fills buf with the specified value. If the offset and end are not given, the entire buf will be filled. 214 * @since 9 215 * @syscap SystemCapability.Utils.Lang 216 * @param value The value with which to fill buf 217 * @param [offset = 0] Number of bytes to skip before starting to fill buf 218 * @param [end = buf.length] Where to stop filling buf (not inclusive) 219 * @param [encoding='utf8'] The encoding for value if value is a string 220 * @returns A reference to buf 221 * @throws {BusinessError} 10200001 - The value of "[offset/end]" is out of range. It must be >= 0 and <= [right range]. Received value is: [offset/end] 222 * @throws {BusinessError} 401 - if the input parameters are invalid. 223 */ 224 fill(value: string | Buffer | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): Buffer; 225 226 /** 227 * Compares buf with target and returns a number indicating whether buf comes before, after, 228 * or is the same as target in sort order. Comparison is based on the actual sequence of bytes in each Buffer. 229 * @since 9 230 * @syscap SystemCapability.Utils.Lang 231 * @param target A Buffer or Uint8Array with which to compare buf 232 * @param [targetStart = 0] The offset within target at which to begin comparison 233 * @param [targetEnd = target.length] The offset within target at which to end comparison (not inclusive) 234 * @param [sourceStart = 0] The offset within buf at which to begin comparison 235 * @param [sourceEnd = buf.length] The offset within buf at which to end comparison (not inclusive) 236 * @returns 0 is returned if target is the same as buf 237 * 1 is returned if target should come before buf when sorted. 238 * -1 is returned if target should come after buf when sorted. 239 * @throws {BusinessError} 401 - if the input parameters are invalid. 240 * @throws {BusinessError} 10200001 - The value of "[targetStart/targetEnd/sourceStart/sourceEnd]" is out of range. 241 * It must be >= 0 and <= [right range]. Received value is: [targetStart/targetEnd/sourceStart/sourceEnd] 242 */ 243 compare(target: Buffer | Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1; 244 245 /** 246 * Copies data from a region of buf to a region in target, even if the target memory region overlaps with buf. 247 * If sourceEnd is greater than the length of the target, the length of the target shall prevail, and the extra part will not be overwritten. 248 * @since 9 249 * @syscap SystemCapability.Utils.Lang 250 * @param target A Buffer or Uint8Array to copy into 251 * @param [targetStart = 0] The offset within target at which to begin writing 252 * @param [sourceStart = 0] The offset within buf from which to begin copying 253 * @param [sourceEnd = buf.length] The offset within buf at which to stop copying (not inclusive) 254 * @returns The number of bytes copied 255 * @throws {BusinessError} 401 - if the input parameters are invalid. 256 * @throws {BusinessError} 10200001 - The value of "[targetStart/sourceStart/sourceEnd]" is out of range. It must be >= 0. 257 * Received value is: [targetStart/sourceStart/sourceEnd] 258 */ 259 copy(target: Buffer | Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; 260 261 /** 262 * Returns true if both buf and otherBuffer have exactly the same bytes, false otherwise 263 * @since 9 264 * @syscap SystemCapability.Utils.Lang 265 * @param otherBuffer A Buffer or Uint8Array with which to compare buf 266 * @returns true or false 267 * @throws {BusinessError} 401 - if the input parameters are invalid. 268 */ 269 equals(otherBuffer: Uint8Array | Buffer): boolean; 270 271 /** 272 * Returns true if value was found in buf, false otherwise 273 * @since 9 274 * @syscap SystemCapability.Utils.Lang 275 * @param value What to search for 276 * @param [byteOffset = 0] Where to begin searching in buf. If negative, then offset is calculated from the end of buf 277 * @param [encoding='utf8'] If value is a string, this is its encoding 278 * @returns true or false 279 * @throws {BusinessError} 401 - if the input parameters are invalid. 280 */ 281 includes(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): boolean; 282 283 /** 284 * The index of the first occurrence of value in buf 285 * @since 9 286 * @syscap SystemCapability.Utils.Lang 287 * @param value What to search for 288 * @param [byteOffset = 0] Where to begin searching in buf 289 * @param [encoding='utf8'] If value is a string, this is the encoding used to determine the binary representation of the string that will be searched for in buf 290 * @returns The index of the first occurrence of value in buf, or -1 if buf does not contain value 291 * @throws {BusinessError} 401 - if the input parameters are invalid. 292 */ 293 indexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number; 294 295 /** 296 * Creates and returns an iterator of buf keys (indices). 297 * @since 9 298 * @syscap SystemCapability.Utils.Lang 299 */ 300 keys(): IterableIterator<number>; 301 302 /** 303 * Creates and returns an iterator for buf values (bytes). 304 * @since 9 305 * @syscap SystemCapability.Utils.Lang 306 */ 307 values(): IterableIterator<number>; 308 309 /** 310 * Creates and returns an iterator of [index, byte] pairs from the contents of buf. 311 * @since 9 312 * @syscap SystemCapability.Utils.Lang 313 */ 314 entries(): IterableIterator<[number, number]>; 315 316 /** 317 * The index of the last occurrence of value in buf 318 * @since 9 319 * @syscap SystemCapability.Utils.Lang 320 * @param value What to search for 321 * @param [byteOffset = 0] Where to begin searching in buf 322 * @param [encoding='utf8'] If value is a string, this is the encoding used to determine the binary representation of the string that will be searched for in buf 323 * @returns The index of the last occurrence of value in buf, or -1 if buf does not contain value 324 * @throws {BusinessError} 401 - if the input parameters are invalid. 325 */ 326 lastIndexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number; 327 328 /** 329 * Reads a signed, big-endian 64-bit integer from buf at the specified offset 330 * @since 9 331 * @syscap SystemCapability.Utils.Lang 332 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8 333 * @returns Return a signed, big-endian 64-bit integer 334 * @throws {BusinessError} 401 - if the input parameters are invalid. 335 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 336 */ 337 readBigInt64BE(offset?: number): bigint; 338 339 /** 340 * Reads a signed, little-endian 64-bit integer from buf at the specified offset 341 * @since 9 342 * @syscap SystemCapability.Utils.Lang 343 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8 344 * @returns Return a signed, little-endian 64-bit integer 345 * @throws {BusinessError} 401 - if the input parameters are invalid. 346 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 347 */ 348 readBigInt64LE(offset?: number): bigint; 349 350 /** 351 * Reads a unsigned, big-endian 64-bit integer from buf at the specified offset 352 * @since 9 353 * @syscap SystemCapability.Utils.Lang 354 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8 355 * @returns Return a unsigned, big-endian 64-bit integer 356 * @throws {BusinessError} 401 - if the input parameters are invalid. 357 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 358 */ 359 readBigUInt64BE(offset?: number): bigint; 360 361 /** 362 * Reads a unsigned, little-endian 64-bit integer from buf at the specified offset 363 * @since 9 364 * @syscap SystemCapability.Utils.Lang 365 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8 366 * @returns Return a unsigned, little-endian 64-bit integer 367 * @throws {BusinessError} 401 - if the input parameters are invalid. 368 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 369 */ 370 readBigUInt64LE(offset?: number): bigint; 371 372 /** 373 * Reads a 64-bit, big-endian double from buf at the specified offset 374 * @since 9 375 * @syscap SystemCapability.Utils.Lang 376 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8 377 * @returns Return a 64-bit, big-endian double 378 * @throws {BusinessError} 401 - if the input parameters are invalid. 379 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 380 */ 381 readDoubleBE(offset?: number): number; 382 383 /** 384 * Reads a 64-bit, little-endian double from buf at the specified offset 385 * @since 9 386 * @syscap SystemCapability.Utils.Lang 387 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 8 388 * @returns Return a 64-bit, little-endian double 389 * @throws {BusinessError} 401 - if the input parameters are invalid. 390 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 391 */ 392 readDoubleLE(offset?: number): number; 393 394 /** 395 * Reads a 32-bit, big-endian float from buf at the specified offset 396 * @since 9 397 * @syscap SystemCapability.Utils.Lang 398 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 4 399 * @returns Return a 32-bit, big-endian float 400 * @throws {BusinessError} 401 - if the input parameters are invalid. 401 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 402 */ 403 readFloatBE(offset?: number): number; 404 405 /** 406 * Reads a 32-bit, little-endian float from buf at the specified offset 407 * @since 9 408 * @syscap SystemCapability.Utils.Lang 409 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 4 410 * @returns Return a 32-bit, little-endian float 411 * @throws {BusinessError} 401 - if the input parameters are invalid. 412 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 413 */ 414 readFloatLE(offset?: number): number; 415 416 /** 417 * Reads a signed 8-bit integer from buf at the specified offset 418 * @since 9 419 * @syscap SystemCapability.Utils.Lang 420 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 1 421 * @returns Return a signed 8-bit integer 422 * @throws {BusinessError} 401 - if the input parameters are invalid. 423 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 1. Received value is: [offset] 424 */ 425 readInt8(offset?: number): number; 426 427 /** 428 * Reads a signed, big-endian 16-bit integer from buf at the specified offset 429 * @since 9 430 * @syscap SystemCapability.Utils.Lang 431 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 2 432 * @returns Return a signed, big-endian 16-bit integer 433 * @throws {BusinessError} 401 - if the input parameters are invalid. 434 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset] 435 */ 436 readInt16BE(offset?: number): number; 437 438 /** 439 * Reads a signed, little-endian 16-bit integer from buf at the specified offset 440 * @since 9 441 * @syscap SystemCapability.Utils.Lang 442 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 2 443 * @returns Return a signed, little-endian 16-bit integer 444 * @throws {BusinessError} 401 - if the input parameters are invalid. 445 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset] 446 */ 447 readInt16LE(offset?: number): number; 448 449 /** 450 * Reads a signed, big-endian 32-bit integer from buf at the specified offset 451 * @since 9 452 * @syscap SystemCapability.Utils.Lang 453 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 4 454 * @returns Return a signed, big-endian 32-bit integer 455 * @throws {BusinessError} 401 - if the input parameters are invalid. 456 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 457 */ 458 readInt32BE(offset?: number): number; 459 460 /** 461 * Reads a signed, little-endian 32-bit integer from buf at the specified offset 462 * @since 9 463 * @syscap SystemCapability.Utils.Lang 464 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - 4 465 * @returns Return a signed, little-endian 32-bit integer 466 * @throws {BusinessError} 401 - if the input parameters are invalid. 467 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 468 */ 469 readInt32LE(offset?: number): number; 470 471 /** 472 * Reads byteLength number of bytes from buf at the specified offset and interprets the result as a big-endian, 473 * two's complement signed value supporting up to 48 bits of accuracy 474 * @since 9 475 * @syscap SystemCapability.Utils.Lang 476 * @param offset Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - byteLength 477 * @param byteLength Number of bytes to read. Must satisfy 0 < byteLength <= 6 478 * @returns 479 * @throws {BusinessError} 401 - if the input parameters are invalid. 480 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 481 */ 482 readIntBE(offset: number, byteLength: number): number; 483 484 /** 485 * Reads byteLength number of bytes from buf at the specified offset and interprets the result as a little-endian, 486 * two's complement signed value supporting up to 48 bits of accuracy. 487 * @since 9 488 * @syscap SystemCapability.Utils.Lang 489 * @param offset Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - byteLength 490 * @param byteLength Number of bytes to read. Must satisfy 0 < byteLength <= 6 491 * @returns 492 * @throws {BusinessError} 401 - if the input parameters are invalid. 493 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 494 */ 495 readIntLE(offset: number, byteLength: number): number; 496 497 /** 498 * Reads an unsigned 8-bit integer from buf at the specified offset 499 * @since 9 500 * @syscap SystemCapability.Utils.Lang 501 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 1 502 * @returns Reads an unsigned 8-bit integer 503 * @throws {BusinessError} 401 - if the input parameters are invalid. 504 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 1. Received value is: [offset] 505 */ 506 readUInt8(offset?: number): number; 507 508 /** 509 * Reads an unsigned, big-endian 16-bit integer from buf at the specified offset 510 * @since 9 511 * @syscap SystemCapability.Utils.Lang 512 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2 513 * @returns Reads an unsigned, big-endian 16-bit integer 514 * @throws {BusinessError} 401 - if the input parameters are invalid. 515 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset] 516 */ 517 readUInt16BE(offset?: number): number; 518 519 /** 520 * Reads an unsigned, little-endian 16-bit integer from buf at the specified offset 521 * @since 9 522 * @syscap SystemCapability.Utils.Lang 523 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 2 524 * @returns Reads an unsigned, little-endian 16-bit integer 525 * @throws {BusinessError} 401 - if the input parameters are invalid. 526 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 2. Received value is: [offset] 527 */ 528 readUInt16LE(offset?: number): number; 529 530 /** 531 * Reads an unsigned, big-endian 32-bit integer from buf at the specified offset 532 * @since 9 533 * @syscap SystemCapability.Utils.Lang 534 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4 535 * @returns Reads an unsigned, big-endian 32-bit integer 536 * @throws {BusinessError} 401 - if the input parameters are invalid. 537 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 538 */ 539 readUInt32BE(offset?: number): number; 540 541 /** 542 * Reads an unsigned, little-endian 32-bit integer from buf at the specified offset 543 * @since 9 544 * @syscap SystemCapability.Utils.Lang 545 * @param [offset = 0] Number of bytes to skip before starting to read. Must satisfy 0 <= offset <= buf.length - 4 546 * @returns Reads an unsigned, little-endian 32-bit integer 547 * @throws {BusinessError} 401 - if the input parameters are invalid. 548 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 549 */ 550 readUInt32LE(offset?: number): number; 551 552 /** 553 * Reads byteLength number of bytes from buf at the specified offset and interprets the result as 554 * an unsigned big-endian integer supporting up to 48 bits of accuracy. 555 * @since 9 556 * @syscap SystemCapability.Utils.Lang 557 * @param offset Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - byteLength 558 * @param byteLength Number of bytes to read. Must satisfy 0 < byteLength <= 6 559 * @returns 560 * @throws {BusinessError} 401 - if the input parameters are invalid. 561 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 562 */ 563 readUIntBE(offset: number, byteLength: number): number; 564 565 /** 566 * Reads byteLength number of bytes from buf at the specified offset and interprets the result as an unsigned, 567 * little-endian integer supporting up to 48 bits of accuracy. 568 * @since 9 569 * @syscap SystemCapability.Utils.Lang 570 * @param offset Number of bytes to skip before starting to read. Must satisfy: 0 <= offset <= buf.length - byteLength 571 * @param byteLength Number of bytes to read. Must satisfy 0 < byteLength <= 6 572 * @returns 573 * @throws {BusinessError} 401 - if the input parameters are invalid. 574 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 575 */ 576 readUIntLE(offset: number, byteLength: number): number; 577 578 /** 579 * Returns a new Buffer that references the same memory as the original, but offset and cropped by the start and end indices. 580 * @since 9 581 * @syscap SystemCapability.Utils.Lang 582 * @param [start = 0] Where the new Buffer will start 583 * @param [end = buf.length] Where the new Buffer will end (not inclusive) 584 * @returns Returns a new Buffer that references the same memory as the original 585 */ 586 subarray(start?: number, end?: number): Buffer; 587 588 /** 589 * Interprets buf as an array of unsigned 16-bit integers and swaps the byte order in-place. 590 * @since 9 591 * @syscap SystemCapability.Utils.Lang 592 * @returns A reference to buf 593 * @throws {BusinessError} 10200009 - Buffer size must be a multiple of 16-bits 594 */ 595 swap16(): Buffer; 596 597 /** 598 * Interprets buf as an array of unsigned 32-bit integers and swaps the byte order in-place. 599 * @since 9 600 * @syscap SystemCapability.Utils.Lang 601 * @returns A reference to buf 602 * @throws {BusinessError} 10200009 - Buffer size must be a multiple of 32-bits 603 */ 604 swap32(): Buffer; 605 606 /** 607 * Interprets buf as an array of unsigned 64-bit integers and swaps the byte order in-place. 608 * @since 9 609 * @syscap SystemCapability.Utils.Lang 610 * @returns A reference to buf 611 * @throws {BusinessError} 10200009 - Buffer size must be a multiple of 64-bits 612 */ 613 swap64(): Buffer; 614 615 /** 616 * Returns a JSON representation of buf 617 * @since 9 618 * @syscap SystemCapability.Utils.Lang 619 * @returns Returns a JSON 620 */ 621 toJSON(): Object; 622 623 /** 624 * Decodes buf to a string according to the specified character encoding in encoding 625 * @since 9 626 * @syscap SystemCapability.Utils.Lang 627 * @param [encoding='utf8'] The character encoding to use 628 * @param [start = 0] The byte offset to start decoding at 629 * @param [end = buf.length] The byte offset to stop decoding at (not inclusive) 630 * @throws {BusinessError} 401 - if the input parameters are invalid. 631 */ 632 toString(encoding?: string, start?: number, end?: number): string; 633 634 /** 635 * Writes string to buf at offset according to the character encoding in encoding 636 * @since 9 637 * @syscap SystemCapability.Utils.Lang 638 * @param str Writes string to buf at offset according to the character encoding in encoding 639 * @param [offset = 0] Number of bytes to skip before starting to write string 640 * @param [length = buf.length - offset] Maximum number of bytes to write (written bytes will not exceed buf.length - offset) 641 * @param [encoding='utf8'] The character encoding of string. 642 * @returns Number of bytes written. 643 * @throws {BusinessError} 401 - if the input parameters are invalid. 644 * @throws {BusinessError} 10200001 - The value of "[offset/length]" is out of range. It must be >= 0 and <= buf.length. Received value is: [offset/length] 645 */ 646 write(str: string, offset?: number, length?: number, encoding?: string): number; 647 648 /** 649 * Writes value to buf at the specified offset as big-endian. 650 * @since 9 651 * @syscap SystemCapability.Utils.Lang 652 * @param value Number to be written to buf 653 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8 654 * @returns offset plus the number of bytes written 655 * @throws {BusinessError} 401 - if the input parameters are invalid. 656 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 657 */ 658 writeBigInt64BE(value: bigint, offset?: number): number; 659 660 /** 661 * Writes value to buf at the specified offset as little-endian. 662 * @since 9 663 * @syscap SystemCapability.Utils.Lang 664 * @param value Number to be written to buf 665 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8 666 * @returns offset plus the number of bytes written 667 * @throws {BusinessError} 401 - if the input parameters are invalid. 668 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 669 */ 670 writeBigInt64LE(value: bigint, offset?: number): number; 671 672 /** 673 * Writes value to buf at the specified offset as big-endian. 674 * @since 9 675 * @syscap SystemCapability.Utils.Lang 676 * @param value Number to be written to buf 677 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8 678 * @returns offset plus the number of bytes written 679 * @throws {BusinessError} 401 - if the input parameters are invalid. 680 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 681 */ 682 writeBigUInt64BE(value: bigint, offset?: number): number; 683 684 /** 685 * Writes value to buf at the specified offset as little-endian. 686 * @since 9 687 * @syscap SystemCapability.Utils.Lang 688 * @param value Number to be written to buf 689 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8 690 * @returns offset plus the number of bytes written 691 * @throws {BusinessError} 401 - if the input parameters are invalid. 692 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 693 */ 694 writeBigUInt64LE(value: bigint, offset?: number): number; 695 696 /** 697 * Writes value to buf at the specified offset as big-endian. 698 * @since 9 699 * @syscap SystemCapability.Utils.Lang 700 * @param value Number to be written to buf 701 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8 702 * @returns offset plus the number of bytes written 703 * @throws {BusinessError} 401 - if the input parameters are invalid. 704 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 705 */ 706 writeDoubleBE(value: number, offset?: number): number; 707 708 /** 709 * Writes value to buf at the specified offset as little-endian. 710 * @since 9 711 * @syscap SystemCapability.Utils.Lang 712 * @param value Number to be written to buf 713 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 8 714 * @returns offset plus the number of bytes written 715 * @throws {BusinessError} 401 - if the input parameters are invalid. 716 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 8. Received value is: [offset] 717 */ 718 writeDoubleLE(value: number, offset?: number): number; 719 720 /** 721 * Writes value to buf at the specified offset as big-endian. 722 * @since 9 723 * @syscap SystemCapability.Utils.Lang 724 * @param value Number to be written to buf 725 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 4 726 * @returns offset plus the number of bytes written 727 * @throws {BusinessError} 401 - if the input parameters are invalid. 728 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 729 */ 730 writeFloatBE(value: number, offset?: number): number; 731 732 /** 733 * Writes value to buf at the specified offset as little-endian. 734 * @since 9 735 * @syscap SystemCapability.Utils.Lang 736 * @param value Number to be written to buf 737 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 4 738 * @returns offset plus the number of bytes written 739 * @throws {BusinessError} 401 - if the input parameters are invalid. 740 * @throws {BusinessError} 10200001 - The value of "offset" is out of range. It must be >= 0 and <= buf.length - 4. Received value is: [offset] 741 */ 742 writeFloatLE(value: number, offset?: number): number; 743 744 /** 745 * Writes value to buf at the specified offset. value must be a valid signed 8-bit integer. 746 * @since 9 747 * @syscap SystemCapability.Utils.Lang 748 * @param value Number to be written to buf 749 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 1 750 * @returns offset plus the number of bytes written 751 * @throws {BusinessError} 401 - if the input parameters are invalid. 752 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 753 */ 754 writeInt8(value: number, offset?: number): number; 755 756 /** 757 * Writes value to buf at the specified offset as big-endian. The value must be a valid signed 16-bit integer 758 * @since 9 759 * @syscap SystemCapability.Utils.Lang 760 * @param value Number to be written to buf 761 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 2 762 * @returns offset plus the number of bytes written 763 * @throws {BusinessError} 401 - if the input parameters are invalid. 764 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 765 */ 766 writeInt16BE(value: number, offset?: number): number; 767 768 /** 769 * Writes value to buf at the specified offset as little-endian. The value must be a valid signed 16-bit integer 770 * @since 9 771 * @syscap SystemCapability.Utils.Lang 772 * @param value Number to be written to buf 773 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 2 774 * @returns offset plus the number of bytes written 775 * @throws {BusinessError} 401 - if the input parameters are invalid. 776 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 777 */ 778 writeInt16LE(value: number, offset?: number): number; 779 780 /** 781 * Writes value to buf at the specified offset as big-endian. The value must be a valid signed 32-bit integer. 782 * @since 9 783 * @syscap SystemCapability.Utils.Lang 784 * @param value Number to be written to buf 785 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 4 786 * @returns offset plus the number of bytes written 787 * @throws {BusinessError} 401 - if the input parameters are invalid. 788 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 789 */ 790 writeInt32BE(value: number, offset?: number): number; 791 792 /** 793 * Writes value to buf at the specified offset as little-endian. The value must be a valid signed 32-bit integer. 794 * @since 9 795 * @syscap SystemCapability.Utils.Lang 796 * @param value Number to be written to buf 797 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy: 0 <= offset <= buf.length - 4 798 * @returns offset plus the number of bytes written 799 * @throws {BusinessError} 401 - if the input parameters are invalid. 800 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 801 */ 802 writeInt32LE(value: number, offset?: number): number; 803 804 /** 805 * Writes byteLength bytes of value to buf at the specified offset as big-endian 806 * @since 9 807 * @syscap SystemCapability.Utils.Lang 808 * @param value Number to be written to buf 809 * @param offset Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength 810 * @param byteLength Number of bytes to write. Must satisfy 0 < byteLength <= 6 811 * @returns offset plus the number of bytes written 812 * @throws {BusinessError} 401 - if the input parameters are invalid. 813 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 814 */ 815 writeIntBE(value: number, offset: number, byteLength: number): number; 816 817 /** 818 * Writes byteLength bytes of value to buf at the specified offset as little-endian 819 * @since 9 820 * @syscap SystemCapability.Utils.Lang 821 * @param value Number to be written to buf 822 * @param offset Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength 823 * @param byteLength Number of bytes to write. Must satisfy 0 < byteLength <= 6 824 * @returns offset plus the number of bytes written 825 * @throws {BusinessError} 401 - if the input parameters are invalid. 826 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 827 */ 828 writeIntLE(value : number, offset: number, byteLength: number): number; 829 830 /** 831 * Writes value to buf at the specified offset. value must be a valid unsigned 8-bit integer 832 * @since 9 833 * @syscap SystemCapability.Utils.Lang 834 * @param value Number to be written to buf 835 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 1 836 * @returns offset plus the number of bytes written 837 * @throws {BusinessError} 401 - if the input parameters are invalid. 838 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 839 */ 840 writeUInt8(value: number, offset?: number): number; 841 842 /** 843 * Writes value to buf at the specified offset as big-endian. The value must be a valid unsigned 16-bit integer. 844 * @since 9 845 * @syscap SystemCapability.Utils.Lang 846 * @param value Number to be written to buf 847 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2 848 * @returns offset plus the number of bytes written 849 * @throws {BusinessError} 401 - if the input parameters are invalid. 850 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 851 */ 852 writeUInt16BE(value: number, offset?: number): number; 853 854 /** 855 * Writes value to buf at the specified offset as little-endian. The value must be a valid unsigned 16-bit integer. 856 * @since 9 857 * @syscap SystemCapability.Utils.Lang 858 * @param value Number to be written to buf 859 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 2 860 * @returns offset plus the number of bytes written 861 * @throws {BusinessError} 401 - if the input parameters are invalid. 862 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 863 */ 864 writeUInt16LE(value: number, offset?: number): number; 865 866 /** 867 * Writes value to buf at the specified offset as big-endian. The value must be a valid unsigned 32-bit integer. 868 * @since 9 869 * @syscap SystemCapability.Utils.Lang 870 * @param value Number to be written to buf 871 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4 872 * @returns offset plus the number of bytes written 873 * @throws {BusinessError} 401 - if the input parameters are invalid. 874 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 875 */ 876 writeUInt32BE(value: number, offset?: number): number; 877 878 /** 879 * Writes value to buf at the specified offset as little-endian. The value must be a valid unsigned 32-bit integer. 880 * @since 9 881 * @syscap SystemCapability.Utils.Lang 882 * @param value Number to be written to buf 883 * @param [offset = 0] Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - 4 884 * @returns offset plus the number of bytes written 885 * @throws {BusinessError} 401 - if the input parameters are invalid. 886 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 887 */ 888 writeUInt32LE(value: number, offset?: number): number; 889 890 /** 891 * Writes byteLength bytes of value to buf at the specified offset as big-endian 892 * @since 9 893 * @syscap SystemCapability.Utils.Lang 894 * @param value Number to be written to buf 895 * @param offset Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength 896 * @param byteLength Number of bytes to write. Must satisfy 0 < byteLength <= 6 897 * @returns offset plus the number of bytes written 898 * @throws {BusinessError} 401 - if the input parameters are invalid. 899 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 900 */ 901 writeUIntBE(value: number, offset: number, byteLength: number): number; 902 903 /** 904 * Writes byteLength bytes of value to buf at the specified offset as little-endian 905 * @since 9 906 * @syscap SystemCapability.Utils.Lang 907 * @param value Number to be written to buf 908 * @param offset Number of bytes to skip before starting to write. Must satisfy 0 <= offset <= buf.length - byteLength 909 * @param byteLength Number of bytes to write. Must satisfy 0 < byteLength <= 6 910 * @returns offset plus the number of bytes written 911 * @throws {BusinessError} 401 - if the input parameters are invalid. 912 * @throws {BusinessError} 10200001 - The value of "[param]" is out of range. It must be >= [left range] and <= [right range]. Received value is: [param] 913 */ 914 writeUIntLE(value: number, offset: number, byteLength: number): number; 915 916 } 917 918 class Blob { 919 920 /** 921 * Creates a new Blob object containing a concatenation of the given sources. 922 * @since 9 923 * @syscap SystemCapability.Utils.Lang 924 * @param sources An array of string, <ArrayBuffer>, <TypedArray>, <DataView>, or <Blob> objects, or any mix of such objects, that will be stored within the Blob 925 * @param options {endings: string, type: string} 926 * endings: One of either 'transparent' or 'native'. 927 * type: The Blob content-type 928 * @throws {BusinessError} 401 - if the input parameters are invalid. 929 */ 930 constructor(sources: string[] | ArrayBuffer[] | TypedArray[] | DataView[] | Blob[] , options?: Object); 931 932 /** 933 * The total size of the Blob in bytes 934 * @since 9 935 * @syscap SystemCapability.Utils.Lang 936 */ 937 size: number; 938 939 /** 940 * The content-type of the Blob 941 * @since 9 942 * @syscap SystemCapability.Utils.Lang 943 */ 944 type: string; 945 946 /** 947 * Returns a promise that fulfills with an <ArrayBuffer> containing a copy of the Blob data. 948 * @since 9 949 * @syscap SystemCapability.Utils.Lang 950 */ 951 arrayBuffer(): Promise<ArrayBuffer>; 952 953 /** 954 * Creates and returns a new Blob containing a subset of this Blob objects data. The original Blob is not altered 955 * @since 9 956 * @syscap SystemCapability.Utils.Lang 957 * @param start The starting index 958 * @param end The ending index 959 * @param type The content-type for the new Blob 960 */ 961 slice(start?: number, end?: number, type?: string): Blob; 962 963 /** 964 * Returns a promise that fulfills with the contents of the Blob decoded as a UTF-8 string. 965 * @since 9 966 * @syscap SystemCapability.Utils.Lang 967 */ 968 text(): Promise<string>; 969 } 970 971} 972export default buffer; 973