@loaders.gl/parquet 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +269 -616
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/lib/arrow/convert-columns-to-row-group.js +1 -2
- package/dist/lib/arrow/convert-row-group-to-columns.js +8 -6
- package/dist/lib/arrow/convert-schema-from-parquet.d.ts +3 -3
- package/dist/lib/arrow/convert-schema-from-parquet.d.ts.map +1 -1
- package/dist/lib/arrow/convert-schema-from-parquet.js +71 -82
- package/dist/lib/arrow/convert-schema-to-parquet.d.ts +1 -1
- package/dist/lib/arrow/convert-schema-to-parquet.d.ts.map +1 -1
- package/dist/lib/arrow/convert-schema-to-parquet.js +65 -35
- package/dist/lib/constants.js +14 -1
- package/dist/lib/parsers/get-parquet-schema.d.ts +1 -1
- package/dist/lib/parsers/get-parquet-schema.d.ts.map +1 -1
- package/dist/lib/parsers/get-parquet-schema.js +9 -7
- package/dist/lib/parsers/parse-geoparquet.d.ts +1 -1
- package/dist/lib/parsers/parse-geoparquet.d.ts.map +1 -1
- package/dist/lib/parsers/parse-geoparquet.js +47 -45
- package/dist/lib/parsers/parse-parquet-to-columns.d.ts +1 -1
- package/dist/lib/parsers/parse-parquet-to-columns.d.ts.map +1 -1
- package/dist/lib/parsers/parse-parquet-to-columns.js +36 -25
- package/dist/lib/parsers/parse-parquet.d.ts +1 -1
- package/dist/lib/parsers/parse-parquet.d.ts.map +1 -1
- package/dist/lib/parsers/parse-parquet.js +62 -50
- package/dist/lib/wasm/encode-parquet-wasm.d.ts +1 -1
- package/dist/lib/wasm/encode-parquet-wasm.d.ts.map +1 -1
- package/dist/lib/wasm/encode-parquet-wasm.js +49 -12
- package/dist/lib/wasm/load-wasm.js +13 -10
- package/dist/lib/wasm/parse-parquet-wasm.d.ts +1 -1
- package/dist/lib/wasm/parse-parquet-wasm.d.ts.map +1 -1
- package/dist/lib/wasm/parse-parquet-wasm.js +19 -15
- package/dist/parquet-loader.d.ts +1 -1
- package/dist/parquet-loader.d.ts.map +1 -1
- package/dist/parquet-loader.js +77 -64
- package/dist/parquet-wasm-loader.js +25 -28
- package/dist/parquet-wasm-writer.js +19 -23
- package/dist/parquet-writer.js +16 -12
- package/dist/parquetjs/codecs/declare.d.ts +1 -1
- package/dist/parquetjs/codecs/declare.d.ts.map +1 -1
- package/dist/parquetjs/codecs/declare.js +0 -1
- package/dist/parquetjs/codecs/dictionary.js +4 -8
- package/dist/parquetjs/codecs/index.d.ts +3 -3
- package/dist/parquetjs/codecs/index.d.ts.map +1 -1
- package/dist/parquetjs/codecs/index.js +20 -17
- package/dist/parquetjs/codecs/plain.d.ts +2 -2
- package/dist/parquetjs/codecs/plain.d.ts.map +1 -1
- package/dist/parquetjs/codecs/plain.js +166 -162
- package/dist/parquetjs/codecs/rle.d.ts +2 -2
- package/dist/parquetjs/codecs/rle.d.ts.map +1 -1
- package/dist/parquetjs/codecs/rle.js +124 -105
- package/dist/parquetjs/compression.d.ts +1 -1
- package/dist/parquetjs/compression.d.ts.map +1 -1
- package/dist/parquetjs/compression.js +157 -43
- package/dist/parquetjs/encoder/parquet-encoder.d.ts +3 -3
- package/dist/parquetjs/encoder/parquet-encoder.d.ts.map +1 -1
- package/dist/parquetjs/encoder/parquet-encoder.js +406 -275
- package/dist/parquetjs/parquet-thrift/BoundaryOrder.js +12 -7
- package/dist/parquetjs/parquet-thrift/BsonType.js +31 -27
- package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnChunk.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnChunk.js +175 -166
- package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnIndex.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnIndex.js +178 -166
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts +6 -6
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.js +359 -333
- package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnOrder.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/ColumnOrder.js +73 -68
- package/dist/parquetjs/parquet-thrift/CompressionCodec.js +17 -12
- package/dist/parquetjs/parquet-thrift/ConvertedType.js +31 -26
- package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/DataPageHeader.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeader.js +136 -124
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.js +198 -181
- package/dist/parquetjs/parquet-thrift/DateType.js +31 -27
- package/dist/parquetjs/parquet-thrift/DecimalType.js +76 -69
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.js +93 -86
- package/dist/parquetjs/parquet-thrift/Encoding.js +17 -12
- package/dist/parquetjs/parquet-thrift/EnumType.js +31 -27
- package/dist/parquetjs/parquet-thrift/FieldRepetitionType.js +12 -7
- package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts +4 -4
- package/dist/parquetjs/parquet-thrift/FileMetaData.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/FileMetaData.js +217 -205
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.js +31 -27
- package/dist/parquetjs/parquet-thrift/IntType.js +76 -69
- package/dist/parquetjs/parquet-thrift/JsonType.js +31 -27
- package/dist/parquetjs/parquet-thrift/KeyValue.js +73 -67
- package/dist/parquetjs/parquet-thrift/ListType.js +31 -27
- package/dist/parquetjs/parquet-thrift/LogicalType.d.ts +13 -13
- package/dist/parquetjs/parquet-thrift/LogicalType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/LogicalType.js +325 -344
- package/dist/parquetjs/parquet-thrift/MapType.js +31 -27
- package/dist/parquetjs/parquet-thrift/MicroSeconds.js +31 -27
- package/dist/parquetjs/parquet-thrift/MilliSeconds.js +31 -27
- package/dist/parquetjs/parquet-thrift/NullType.js +31 -27
- package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/OffsetIndex.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/OffsetIndex.js +66 -60
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.js +98 -88
- package/dist/parquetjs/parquet-thrift/PageHeader.d.ts +5 -5
- package/dist/parquetjs/parquet-thrift/PageHeader.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/PageHeader.js +185 -175
- package/dist/parquetjs/parquet-thrift/PageLocation.js +108 -96
- package/dist/parquetjs/parquet-thrift/PageType.js +13 -8
- package/dist/parquetjs/parquet-thrift/RowGroup.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/RowGroup.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/RowGroup.js +145 -133
- package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts +4 -4
- package/dist/parquetjs/parquet-thrift/SchemaElement.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/SchemaElement.js +211 -205
- package/dist/parquetjs/parquet-thrift/SortingColumn.js +98 -88
- package/dist/parquetjs/parquet-thrift/Statistics.js +143 -137
- package/dist/parquetjs/parquet-thrift/StringType.js +31 -27
- package/dist/parquetjs/parquet-thrift/TimeType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/TimeType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimeType.js +76 -69
- package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts +2 -2
- package/dist/parquetjs/parquet-thrift/TimeUnit.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimeUnit.js +94 -91
- package/dist/parquetjs/parquet-thrift/TimestampType.d.ts +1 -1
- package/dist/parquetjs/parquet-thrift/TimestampType.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/TimestampType.js +76 -69
- package/dist/parquetjs/parquet-thrift/Type.js +17 -12
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.js +31 -27
- package/dist/parquetjs/parquet-thrift/UUIDType.js +31 -27
- package/dist/parquetjs/parquet-thrift/index.d.ts +44 -44
- package/dist/parquetjs/parquet-thrift/index.d.ts.map +1 -1
- package/dist/parquetjs/parquet-thrift/index.js +6 -1
- package/dist/parquetjs/parser/decoders.d.ts +3 -3
- package/dist/parquetjs/parser/decoders.d.ts.map +1 -1
- package/dist/parquetjs/parser/decoders.js +306 -242
- package/dist/parquetjs/parser/parquet-reader.d.ts +3 -3
- package/dist/parquetjs/parser/parquet-reader.d.ts.map +1 -1
- package/dist/parquetjs/parser/parquet-reader.js +179 -157
- package/dist/parquetjs/schema/declare.d.ts +1 -1
- package/dist/parquetjs/schema/declare.d.ts.map +1 -1
- package/dist/parquetjs/schema/declare.js +6 -9
- package/dist/parquetjs/schema/schema.d.ts +1 -1
- package/dist/parquetjs/schema/schema.d.ts.map +1 -1
- package/dist/parquetjs/schema/schema.js +139 -120
- package/dist/parquetjs/schema/shred.d.ts +2 -2
- package/dist/parquetjs/schema/shred.d.ts.map +1 -1
- package/dist/parquetjs/schema/shred.js +301 -204
- package/dist/parquetjs/schema/types.d.ts +1 -1
- package/dist/parquetjs/schema/types.d.ts.map +1 -1
- package/dist/parquetjs/schema/types.js +328 -314
- package/dist/parquetjs/utils/file-utils.js +24 -23
- package/dist/parquetjs/utils/read-utils.d.ts +1 -1
- package/dist/parquetjs/utils/read-utils.d.ts.map +1 -1
- package/dist/parquetjs/utils/read-utils.js +79 -69
- package/dist/polyfills/buffer/buffer-polyfill.browser.js +8 -3
- package/dist/polyfills/buffer/buffer-polyfill.node.js +13 -8
- package/dist/polyfills/buffer/buffer.js +1750 -1367
- package/dist/polyfills/buffer/index.d.ts +3 -3
- package/dist/polyfills/buffer/index.d.ts.map +1 -1
- package/dist/polyfills/buffer/index.js +5 -1
- package/dist/polyfills/buffer/install-buffer-polyfill.js +2 -1
- package/dist/polyfills/util.js +4 -1
- package/dist/workers/parquet-worker.js +3 -1
- package/package.json +15 -13
- package/src/index.ts +1 -1
- package/src/lib/parsers/parse-parquet-to-columns.ts +1 -1
- package/src/lib/parsers/parse-parquet.ts +1 -1
- package/src/parquetjs/encoder/parquet-encoder.ts +2 -2
- package/src/parquetjs/parser/decoders.ts +2 -2
- package/src/parquetjs/parser/parquet-reader.ts +1 -1
- package/src/parquetjs/schema/schema.ts +1 -1
- package/src/parquetjs/utils/read-utils.ts +2 -2
- package/dist/index.js.map +0 -1
- package/dist/lib/arrow/convert-columns-to-row-group.js.map +0 -1
- package/dist/lib/arrow/convert-row-group-to-columns.js.map +0 -1
- package/dist/lib/arrow/convert-schema-from-parquet.js.map +0 -1
- package/dist/lib/arrow/convert-schema-to-parquet.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/parsers/get-parquet-schema.js.map +0 -1
- package/dist/lib/parsers/parse-geoparquet.js.map +0 -1
- package/dist/lib/parsers/parse-parquet-to-columns.js.map +0 -1
- package/dist/lib/parsers/parse-parquet.js.map +0 -1
- package/dist/lib/wasm/encode-parquet-wasm.js.map +0 -1
- package/dist/lib/wasm/load-wasm.js.map +0 -1
- package/dist/lib/wasm/parse-parquet-wasm.js.map +0 -1
- package/dist/lib/wip/convert-schema-deep.java.disabled +0 -910
- package/dist/lib/wip/convert-schema-deep.rs.disabled +0 -976
- package/dist/parquet-loader.js.map +0 -1
- package/dist/parquet-wasm-loader.js.map +0 -1
- package/dist/parquet-wasm-writer.js.map +0 -1
- package/dist/parquet-writer.js.map +0 -1
- package/dist/parquetjs/LICENSE +0 -20
- package/dist/parquetjs/codecs/declare.js.map +0 -1
- package/dist/parquetjs/codecs/dictionary.js.map +0 -1
- package/dist/parquetjs/codecs/index.js.map +0 -1
- package/dist/parquetjs/codecs/plain.js.map +0 -1
- package/dist/parquetjs/codecs/rle.js.map +0 -1
- package/dist/parquetjs/compression.js.map +0 -1
- package/dist/parquetjs/encoder/parquet-encoder.js.map +0 -1
- package/dist/parquetjs/modules.d.ts +0 -21
- package/dist/parquetjs/parquet-thrift/BoundaryOrder.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/BsonType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/ColumnChunk.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/ColumnIndex.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/ColumnMetaData.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/ColumnOrder.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/CompressionCodec.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/ConvertedType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeader.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/DataPageHeaderV2.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/DateType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/DecimalType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/DictionaryPageHeader.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/Encoding.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/EnumType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/FieldRepetitionType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/FileMetaData.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/IndexPageHeader.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/IntType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/JsonType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/KeyValue.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/ListType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/LogicalType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/MapType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/MicroSeconds.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/MilliSeconds.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/NullType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/OffsetIndex.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/PageEncodingStats.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/PageHeader.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/PageLocation.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/PageType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/RowGroup.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/SchemaElement.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/SortingColumn.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/Statistics.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/StringType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/TimeType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/TimeUnit.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/TimestampType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/Type.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/TypeDefinedOrder.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/UUIDType.js.map +0 -1
- package/dist/parquetjs/parquet-thrift/index.js.map +0 -1
- package/dist/parquetjs/parser/decoders.js.map +0 -1
- package/dist/parquetjs/parser/parquet-reader.js.map +0 -1
- package/dist/parquetjs/schema/declare.js.map +0 -1
- package/dist/parquetjs/schema/schema.js.map +0 -1
- package/dist/parquetjs/schema/shred.js.map +0 -1
- package/dist/parquetjs/schema/types.js.map +0 -1
- package/dist/parquetjs/utils/file-utils.js.map +0 -1
- package/dist/parquetjs/utils/read-utils.js.map +0 -1
- package/dist/polyfills/buffer/buffer-polyfill.browser.js.map +0 -1
- package/dist/polyfills/buffer/buffer-polyfill.node.js.map +0 -1
- package/dist/polyfills/buffer/buffer.js.map +0 -1
- package/dist/polyfills/buffer/index.js.map +0 -1
- package/dist/polyfills/buffer/install-buffer-polyfill.js.map +0 -1
- package/dist/polyfills/util.js.map +0 -1
- package/dist/workers/parquet-worker.js.map +0 -1
|
@@ -1,1488 +1,1871 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// This file is forked from https://github.com/feross/buffer under MIT license
|
|
5
|
+
// The code has primarily been converted to TypeScript.
|
|
1
6
|
/* !
|
|
2
7
|
* The buffer module from node.js, for the browser.
|
|
3
8
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
4
9
|
* @license MIT
|
|
5
10
|
* https://github.com/feross/buffer/blob/master/AUTHORS.md
|
|
6
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* The decision to include this polyfill in loaders.gl may seem controversial.
|
|
14
|
+
*
|
|
15
|
+
* It is based on the following reasoning:
|
|
16
|
+
* - The Buffer API is used in the parquetjs library and likely other Node.js
|
|
17
|
+
* libraries we will use in the future.
|
|
18
|
+
* - While the goal is to convert code from Buffer to ArrayBuffer, the Thrift
|
|
19
|
+
* code in Parquet may be autogenerated.
|
|
20
|
+
* - Bundlers often require a polyfill to be included, this extra step is not
|
|
21
|
+
* a great experience for loaders.gl users.
|
|
22
|
+
* - The forked buffer polyfill module had old and generated some type errors.
|
|
23
|
+
*/
|
|
24
|
+
/* eslint-disable */ // no-proto, max-statements, max-depth, complexity, no-continue, prefer-spread, no-constant-condition, consistent-return */
|
|
25
|
+
// @ts-nocheck - this references don't work well in prototype assignment
|
|
7
26
|
import base64 from 'base64-js';
|
|
8
27
|
import ieee754 from 'ieee754';
|
|
9
28
|
export const kMaxLength = 0x7fffffff;
|
|
10
29
|
export const INSPECT_MAX_BYTES = 50;
|
|
30
|
+
// const customInspectSymbol =
|
|
31
|
+
// typeof Symbol === 'function' && typeof Symbol['for'] === 'function' // eslint-disable-line dot-notation
|
|
32
|
+
// ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
|
|
33
|
+
// : null;
|
|
34
|
+
/**
|
|
35
|
+
* The Buffer constructor returns instances of `Uint8Array` that have their
|
|
36
|
+
* prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
|
|
37
|
+
* `Uint8Array`, so the returned instances will have all the node `Buffer` methods
|
|
38
|
+
* and the `Uint8Array` methods. Square bracket notation works as expected -- it
|
|
39
|
+
* returns a single octet.
|
|
40
|
+
*
|
|
41
|
+
* The `Uint8Array` prototype remains unmodified.
|
|
42
|
+
*/
|
|
11
43
|
export class Buffer extends Uint8Array {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
44
|
+
// length: number; inherited
|
|
45
|
+
get parent() {
|
|
46
|
+
if (!Buffer.isBuffer(this))
|
|
47
|
+
return undefined;
|
|
48
|
+
return this.buffer;
|
|
49
|
+
}
|
|
50
|
+
get offset() {
|
|
51
|
+
if (!Buffer.isBuffer(this))
|
|
52
|
+
return undefined;
|
|
53
|
+
return this.byteOffset;
|
|
54
|
+
}
|
|
55
|
+
constructor(arg, encodingOrOffset, length) {
|
|
56
|
+
if (typeof arg !== 'number') {
|
|
57
|
+
return Buffer.from(arg, encodingOrOffset, length);
|
|
58
|
+
}
|
|
59
|
+
// Basic case, just a length
|
|
60
|
+
const size = arg;
|
|
61
|
+
if (size > kMaxLength) {
|
|
62
|
+
throw new RangeError(`The value "${size}" is invalid for option "size"`);
|
|
63
|
+
}
|
|
64
|
+
if (typeof encodingOrOffset === 'string') {
|
|
65
|
+
throw new TypeError('The "string" argument must be of type string. Received type number');
|
|
66
|
+
}
|
|
67
|
+
super(size < 0 ? 0 : checked(size) | 0);
|
|
68
|
+
/** This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
|
|
69
|
+
* to detect a Buffer instance. It's not possible to use `instanceof Buffer`
|
|
70
|
+
* reliably in a browserify context because there could be multiple different
|
|
71
|
+
* copies of the 'buffer' package in use. This method works even for Buffer
|
|
72
|
+
* instances that were created from another copy of the `buffer` package.
|
|
73
|
+
* @see: https://github.com/feross/buffer/issues/154
|
|
74
|
+
*/
|
|
75
|
+
this._isBuffer = true;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
static from(value, encodingOrOffset, length) {
|
|
79
|
+
if (typeof value === 'string') {
|
|
80
|
+
return fromString(value, encodingOrOffset);
|
|
81
|
+
}
|
|
82
|
+
if (ArrayBuffer.isView(value)) {
|
|
83
|
+
return fromArrayView(value);
|
|
84
|
+
}
|
|
85
|
+
if (value == null) {
|
|
86
|
+
throw new TypeError(`${'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
87
|
+
'or Array-like Object. Received type '}${typeof value}`);
|
|
88
|
+
}
|
|
89
|
+
if (isInstance(value, ArrayBuffer) || (value && isInstance(value.buffer, ArrayBuffer))) {
|
|
90
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
91
|
+
}
|
|
92
|
+
if (typeof SharedArrayBuffer !== 'undefined' &&
|
|
93
|
+
(isInstance(value, SharedArrayBuffer) ||
|
|
94
|
+
(value && isInstance(value.buffer, SharedArrayBuffer)))) {
|
|
95
|
+
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === 'number') {
|
|
98
|
+
throw new TypeError('The "value" argument must not be of type number. Received type number');
|
|
99
|
+
}
|
|
100
|
+
const valueOf = value.valueOf && value.valueOf();
|
|
101
|
+
if (valueOf != null && valueOf !== value) {
|
|
102
|
+
return Buffer.from(valueOf, encodingOrOffset, length);
|
|
103
|
+
}
|
|
104
|
+
const b = fromObject(value);
|
|
105
|
+
if (b)
|
|
106
|
+
return b;
|
|
107
|
+
if (typeof Symbol !== 'undefined' &&
|
|
108
|
+
Symbol.toPrimitive != null &&
|
|
109
|
+
typeof value[Symbol.toPrimitive] === 'function') {
|
|
110
|
+
return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length);
|
|
111
|
+
}
|
|
112
|
+
throw new TypeError(`${'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' +
|
|
113
|
+
'or Array-like Object. Received type '}${typeof value}`);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns true if {obj} is a Buffer
|
|
117
|
+
*
|
|
118
|
+
* @param obj object to test.
|
|
119
|
+
*/
|
|
120
|
+
static isBuffer(b) {
|
|
121
|
+
return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The same as buf1.compare(buf2).
|
|
125
|
+
*/
|
|
126
|
+
static compare(a, b) {
|
|
127
|
+
if (!Buffer.isBuffer(a) && isInstance(a, Uint8Array))
|
|
128
|
+
a = Buffer.from(a, a.offset, a.byteLength);
|
|
129
|
+
if (!Buffer.isBuffer(b) && isInstance(b, Uint8Array))
|
|
130
|
+
b = Buffer.from(b, b.offset, b.byteLength);
|
|
131
|
+
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
|
|
132
|
+
throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
|
|
133
|
+
}
|
|
134
|
+
if (a === b)
|
|
135
|
+
return 0;
|
|
136
|
+
let x = a.length;
|
|
137
|
+
let y = b.length;
|
|
138
|
+
for (let i = 0, len = Math.min(x, y); i < len; ++i) {
|
|
139
|
+
if (a[i] !== b[i]) {
|
|
140
|
+
x = a[i];
|
|
141
|
+
y = b[i];
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (x < y)
|
|
146
|
+
return -1;
|
|
147
|
+
if (y < x)
|
|
148
|
+
return 1;
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Returns true if {encoding} is a valid encoding argument.
|
|
153
|
+
* Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex'
|
|
154
|
+
*
|
|
155
|
+
* @param encoding string to test.
|
|
156
|
+
*/
|
|
157
|
+
static isEncoding(encoding) {
|
|
158
|
+
switch (String(encoding).toLowerCase()) {
|
|
159
|
+
case 'hex':
|
|
160
|
+
case 'utf8':
|
|
161
|
+
case 'utf-8':
|
|
162
|
+
case 'ascii':
|
|
163
|
+
case 'latin1':
|
|
164
|
+
case 'binary':
|
|
165
|
+
case 'base64':
|
|
166
|
+
case 'ucs2':
|
|
167
|
+
case 'ucs-2':
|
|
168
|
+
case 'utf16le':
|
|
169
|
+
case 'utf-16le':
|
|
170
|
+
return true;
|
|
171
|
+
default:
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
112
174
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Returns a buffer which is the result of concatenating all the buffers in the list together.
|
|
177
|
+
*
|
|
178
|
+
* If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer.
|
|
179
|
+
* If the list has exactly one item, then the first item of the list is returned.
|
|
180
|
+
* If the list has more than one item, then a new Buffer is created.
|
|
181
|
+
*
|
|
182
|
+
* @param list An array of Buffer objects to concatenate
|
|
183
|
+
* @param totalLength Total length of the buffers when concatenated.
|
|
184
|
+
* If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly.
|
|
185
|
+
*/
|
|
186
|
+
static concat(list, length) {
|
|
187
|
+
if (!Array.isArray(list)) {
|
|
188
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
189
|
+
}
|
|
190
|
+
if (list.length === 0) {
|
|
191
|
+
return Buffer.alloc(0);
|
|
192
|
+
}
|
|
193
|
+
let i;
|
|
194
|
+
if (length === undefined) {
|
|
195
|
+
length = 0;
|
|
196
|
+
for (i = 0; i < list.length; ++i) {
|
|
197
|
+
length += list[i].length;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
201
|
+
let pos = 0;
|
|
202
|
+
for (i = 0; i < list.length; ++i) {
|
|
203
|
+
let buf = list[i];
|
|
204
|
+
if (isInstance(buf, Uint8Array)) {
|
|
205
|
+
if (pos + buf.length > buffer.length) {
|
|
206
|
+
if (!Buffer.isBuffer(buf)) {
|
|
207
|
+
buf = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
208
|
+
}
|
|
209
|
+
buf.copy(buffer, pos);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
Uint8Array.prototype.set.call(buffer, buf, pos);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else if (!Buffer.isBuffer(buf)) {
|
|
216
|
+
throw new TypeError('"list" argument must be an Array of Buffers');
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
buf.copy(buffer, pos);
|
|
220
|
+
}
|
|
221
|
+
pos += buf.length;
|
|
222
|
+
}
|
|
223
|
+
return buffer;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Allocates a new buffer of {size} octets.
|
|
227
|
+
*
|
|
228
|
+
* @param size count of octets to allocate.
|
|
229
|
+
* @param fill if specified, buffer will be initialized by calling buf.fill(fill).
|
|
230
|
+
* If parameter is omitted, buffer will be filled with zeros.
|
|
231
|
+
* @param encoding encoding used for call to buf.fill while initializing
|
|
232
|
+
*/
|
|
233
|
+
static alloc(size, fill, encoding) {
|
|
234
|
+
return alloc(size, fill, encoding);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents
|
|
238
|
+
* of the newly created Buffer are unknown and may contain sensitive data.
|
|
239
|
+
*
|
|
240
|
+
* @param size count of octets to allocate
|
|
241
|
+
*/
|
|
242
|
+
static allocUnsafe(size) {
|
|
243
|
+
assertSize(size);
|
|
244
|
+
return new Buffer(size);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents
|
|
248
|
+
* of the newly created Buffer are unknown and may contain sensitive data.
|
|
249
|
+
*
|
|
250
|
+
* @param size count of octets to allocate
|
|
251
|
+
*/
|
|
252
|
+
static allocUnsafeSlow(size) {
|
|
253
|
+
return allocUnsafe(size);
|
|
254
|
+
}
|
|
255
|
+
includes(val, byteOffset, encoding) {
|
|
256
|
+
return this.indexOf(val, byteOffset, encoding) !== -1;
|
|
257
|
+
}
|
|
258
|
+
indexOf(val, byteOffset, encoding) {
|
|
259
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
|
|
260
|
+
}
|
|
261
|
+
lastIndexOf(val, byteOffset, encoding) {
|
|
262
|
+
return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
|
|
263
|
+
}
|
|
264
|
+
readInt8(offset, noAssert) {
|
|
265
|
+
offset = offset >>> 0;
|
|
266
|
+
if (!noAssert)
|
|
267
|
+
checkOffset(offset, 1, this.length);
|
|
268
|
+
if (!(this[offset] & 0x80))
|
|
269
|
+
return this[offset];
|
|
270
|
+
return (0xff - this[offset] + 1) * -1;
|
|
271
|
+
}
|
|
272
|
+
readInt16LE(offset, noAssert) {
|
|
273
|
+
offset = offset >>> 0;
|
|
274
|
+
if (!noAssert)
|
|
275
|
+
checkOffset(offset, 2, this.length);
|
|
276
|
+
const val = this[offset] | (this[offset + 1] << 8);
|
|
277
|
+
return val & 0x8000 ? val | 0xffff0000 : val;
|
|
278
|
+
}
|
|
279
|
+
readInt16BE(offset, noAssert) {
|
|
280
|
+
offset = offset >>> 0;
|
|
281
|
+
if (!noAssert)
|
|
282
|
+
checkOffset(offset, 2, this.length);
|
|
283
|
+
const val = this[offset + 1] | (this[offset] << 8);
|
|
284
|
+
return val & 0x8000 ? val | 0xffff0000 : val;
|
|
285
|
+
}
|
|
286
|
+
readInt32LE(offset, noAssert) {
|
|
287
|
+
offset = offset >>> 0;
|
|
288
|
+
if (!noAssert)
|
|
289
|
+
checkOffset(offset, 4, this.length);
|
|
290
|
+
return (this[offset] | (this[offset + 1] << 8) | (this[offset + 2] << 16) | (this[offset + 3] << 24));
|
|
291
|
+
}
|
|
292
|
+
readInt32BE(offset, noAssert) {
|
|
293
|
+
offset = offset >>> 0;
|
|
294
|
+
if (!noAssert)
|
|
295
|
+
checkOffset(offset, 4, this.length);
|
|
296
|
+
return ((this[offset] << 24) | (this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3]);
|
|
297
|
+
}
|
|
298
|
+
readIntBE(offset, byteLength, noAssert) {
|
|
299
|
+
offset = offset >>> 0;
|
|
300
|
+
byteLength = byteLength >>> 0;
|
|
301
|
+
if (!noAssert)
|
|
302
|
+
checkOffset(offset, byteLength, this.length);
|
|
303
|
+
let i = byteLength;
|
|
304
|
+
let mul = 1;
|
|
305
|
+
let val = this[offset + --i];
|
|
306
|
+
while (i > 0 && (mul *= 0x100)) {
|
|
307
|
+
val += this[offset + --i] * mul;
|
|
308
|
+
}
|
|
309
|
+
mul *= 0x80;
|
|
310
|
+
if (val >= mul)
|
|
311
|
+
val -= Math.pow(2, 8 * byteLength);
|
|
312
|
+
return val;
|
|
313
|
+
}
|
|
314
|
+
readIntLE(offset, byteLength, noAssert) {
|
|
315
|
+
offset = offset >>> 0;
|
|
316
|
+
byteLength = byteLength >>> 0;
|
|
317
|
+
if (!noAssert)
|
|
318
|
+
checkOffset(offset, byteLength, this.length);
|
|
319
|
+
let val = this[offset];
|
|
320
|
+
let mul = 1;
|
|
321
|
+
let i = 0;
|
|
322
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
323
|
+
val += this[offset + i] * mul;
|
|
324
|
+
}
|
|
325
|
+
mul *= 0x80;
|
|
326
|
+
if (val >= mul)
|
|
327
|
+
val -= Math.pow(2, 8 * byteLength);
|
|
328
|
+
return val;
|
|
329
|
+
}
|
|
330
|
+
readBigInt64LE(offset) {
|
|
331
|
+
offset = offset >>> 0;
|
|
332
|
+
validateNumber(offset, 'offset');
|
|
333
|
+
const first = this[offset];
|
|
334
|
+
const last = this[offset + 7];
|
|
335
|
+
if (first === undefined || last === undefined) {
|
|
336
|
+
boundsError(offset, this.length - 8);
|
|
337
|
+
}
|
|
338
|
+
const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24); // Overflow
|
|
339
|
+
return ((BigInt(val) << BigInt(32)) +
|
|
340
|
+
BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24));
|
|
341
|
+
}
|
|
342
|
+
readBigInt64BE(offset) {
|
|
343
|
+
offset = offset >>> 0;
|
|
344
|
+
validateNumber(offset, 'offset');
|
|
345
|
+
const first = this[offset];
|
|
346
|
+
const last = this[offset + 7];
|
|
347
|
+
if (first === undefined || last === undefined) {
|
|
348
|
+
boundsError(offset, this.length - 8);
|
|
349
|
+
}
|
|
350
|
+
const val = (first << 24) + // Overflow
|
|
351
|
+
this[++offset] * 2 ** 16 +
|
|
352
|
+
this[++offset] * 2 ** 8 +
|
|
353
|
+
this[++offset];
|
|
354
|
+
return ((BigInt(val) << BigInt(32)) +
|
|
355
|
+
BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last));
|
|
356
|
+
}
|
|
357
|
+
readUInt8(offset, noAssert) {
|
|
358
|
+
offset = offset >>> 0;
|
|
359
|
+
if (!noAssert)
|
|
360
|
+
checkOffset(offset, 1, this.length);
|
|
361
|
+
return this[offset];
|
|
362
|
+
}
|
|
363
|
+
readUInt16LE(offset, noAssert) {
|
|
364
|
+
offset = offset >>> 0;
|
|
365
|
+
if (!noAssert)
|
|
366
|
+
checkOffset(offset, 2, this.length);
|
|
367
|
+
return this[offset] | (this[offset + 1] << 8);
|
|
368
|
+
}
|
|
369
|
+
readUInt16BE(offset, noAssert) {
|
|
370
|
+
offset = offset >>> 0;
|
|
371
|
+
if (!noAssert)
|
|
372
|
+
checkOffset(offset, 2, this.length);
|
|
373
|
+
return (this[offset] << 8) | this[offset + 1];
|
|
374
|
+
}
|
|
375
|
+
readUInt32LE(offset, noAssert) {
|
|
376
|
+
offset = offset >>> 0;
|
|
377
|
+
if (!noAssert)
|
|
378
|
+
checkOffset(offset, 4, this.length);
|
|
379
|
+
return ((this[offset] | (this[offset + 1] << 8) | (this[offset + 2] << 16)) +
|
|
380
|
+
this[offset + 3] * 0x1000000);
|
|
381
|
+
}
|
|
382
|
+
readUInt32BE(offset, noAssert) {
|
|
383
|
+
offset = offset >>> 0;
|
|
384
|
+
if (!noAssert)
|
|
385
|
+
checkOffset(offset, 4, this.length);
|
|
386
|
+
return (this[offset] * 0x1000000 +
|
|
387
|
+
((this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3]));
|
|
388
|
+
}
|
|
389
|
+
readUIntLE(offset, byteLength, noAssert) {
|
|
390
|
+
offset = offset >>> 0;
|
|
391
|
+
byteLength = byteLength >>> 0;
|
|
392
|
+
if (!noAssert)
|
|
393
|
+
checkOffset(offset, byteLength, this.length);
|
|
394
|
+
let val = this[offset];
|
|
395
|
+
let mul = 1;
|
|
396
|
+
let i = 0;
|
|
397
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
398
|
+
val += this[offset + i] * mul;
|
|
399
|
+
}
|
|
400
|
+
return val;
|
|
273
401
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
402
|
+
readUIntBE(offset, byteLength, noAssert) {
|
|
403
|
+
offset = offset >>> 0;
|
|
404
|
+
byteLength = byteLength >>> 0;
|
|
405
|
+
if (!noAssert) {
|
|
406
|
+
checkOffset(offset, byteLength, this.length);
|
|
407
|
+
}
|
|
408
|
+
let val = this[offset + --byteLength];
|
|
409
|
+
let mul = 1;
|
|
410
|
+
while (byteLength > 0 && (mul *= 0x100)) {
|
|
411
|
+
val += this[offset + --byteLength] * mul;
|
|
412
|
+
}
|
|
413
|
+
return val;
|
|
414
|
+
}
|
|
415
|
+
readBigUInt64LE(offset) {
|
|
416
|
+
offset = offset >>> 0;
|
|
417
|
+
validateNumber(offset, 'offset');
|
|
418
|
+
const first = this[offset];
|
|
419
|
+
const last = this[offset + 7];
|
|
420
|
+
if (first === undefined || last === undefined) {
|
|
421
|
+
boundsError(offset, this.length - 8);
|
|
422
|
+
}
|
|
423
|
+
const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
424
|
+
const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
425
|
+
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
426
|
+
}
|
|
427
|
+
readBigUInt64BE(offset) {
|
|
428
|
+
offset = offset >>> 0;
|
|
429
|
+
validateNumber(offset, 'offset');
|
|
430
|
+
const first = this[offset];
|
|
431
|
+
const last = this[offset + 7];
|
|
432
|
+
if (first === undefined || last === undefined) {
|
|
433
|
+
boundsError(offset, this.length - 8);
|
|
434
|
+
}
|
|
435
|
+
const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
436
|
+
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
437
|
+
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
438
|
+
}
|
|
439
|
+
readFloatLE(offset, noAssert) {
|
|
440
|
+
offset = offset >>> 0;
|
|
441
|
+
if (!noAssert)
|
|
442
|
+
checkOffset(offset, 4, this.length);
|
|
443
|
+
return ieee754.read(this, offset, true, 23, 4);
|
|
444
|
+
}
|
|
445
|
+
readFloatBE(offset, noAssert) {
|
|
446
|
+
offset = offset >>> 0;
|
|
447
|
+
if (!noAssert)
|
|
448
|
+
checkOffset(offset, 4, this.length);
|
|
449
|
+
return ieee754.read(this, offset, false, 23, 4);
|
|
450
|
+
}
|
|
451
|
+
readDoubleLE(offset, noAssert) {
|
|
452
|
+
offset = offset >>> 0;
|
|
453
|
+
if (!noAssert)
|
|
454
|
+
checkOffset(offset, 8, this.length);
|
|
455
|
+
return ieee754.read(this, offset, true, 52, 8);
|
|
456
|
+
}
|
|
457
|
+
readDoubleBE(offset, noAssert) {
|
|
458
|
+
offset = offset >>> 0;
|
|
459
|
+
if (!noAssert)
|
|
460
|
+
checkOffset(offset, 8, this.length);
|
|
461
|
+
return ieee754.read(this, offset, false, 52, 8);
|
|
462
|
+
}
|
|
463
|
+
writeUInt8(value, offset, noAssert) {
|
|
464
|
+
value = Number(value);
|
|
465
|
+
offset = offset >>> 0;
|
|
466
|
+
if (!noAssert)
|
|
467
|
+
checkInt(this, value, offset, 1, 0xff, 0);
|
|
468
|
+
this[offset] = value & 0xff;
|
|
469
|
+
return offset + 1;
|
|
470
|
+
}
|
|
471
|
+
writeUInt16LE(value, offset, noAssert) {
|
|
472
|
+
value = Number(value);
|
|
473
|
+
offset = offset >>> 0;
|
|
474
|
+
if (!noAssert)
|
|
475
|
+
checkInt(this, value, offset, 2, 0xffff, 0);
|
|
476
|
+
this[offset] = value & 0xff;
|
|
477
|
+
this[offset + 1] = value >>> 8;
|
|
478
|
+
return offset + 2;
|
|
479
|
+
}
|
|
480
|
+
writeUInt16BE(value, offset, noAssert) {
|
|
481
|
+
value = Number(value);
|
|
482
|
+
offset = offset >>> 0;
|
|
483
|
+
if (!noAssert)
|
|
484
|
+
checkInt(this, value, offset, 2, 0xffff, 0);
|
|
485
|
+
this[offset] = value >>> 8;
|
|
486
|
+
this[offset + 1] = value & 0xff;
|
|
487
|
+
return offset + 2;
|
|
488
|
+
}
|
|
489
|
+
writeUInt32LE(value, offset, noAssert) {
|
|
490
|
+
value = Number(value);
|
|
491
|
+
offset = offset >>> 0;
|
|
492
|
+
if (!noAssert)
|
|
493
|
+
checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
494
|
+
this[offset + 3] = value >>> 24;
|
|
495
|
+
this[offset + 2] = value >>> 16;
|
|
496
|
+
this[offset + 1] = value >>> 8;
|
|
497
|
+
this[offset] = value & 0xff;
|
|
498
|
+
return offset + 4;
|
|
499
|
+
}
|
|
500
|
+
writeUInt32BE(value, offset, noAssert) {
|
|
501
|
+
value = Number(value);
|
|
502
|
+
offset = offset >>> 0;
|
|
503
|
+
if (!noAssert)
|
|
504
|
+
checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
505
|
+
this[offset] = value >>> 24;
|
|
506
|
+
this[offset + 1] = value >>> 16;
|
|
507
|
+
this[offset + 2] = value >>> 8;
|
|
508
|
+
this[offset + 3] = value & 0xff;
|
|
509
|
+
return offset + 4;
|
|
510
|
+
}
|
|
511
|
+
writeUIntLE(value, offset, byteLength, noAssert) {
|
|
512
|
+
value = Number(value);
|
|
513
|
+
offset = offset >>> 0;
|
|
514
|
+
byteLength = byteLength >>> 0;
|
|
515
|
+
if (!noAssert) {
|
|
516
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
517
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
518
|
+
}
|
|
519
|
+
let mul = 1;
|
|
520
|
+
let i = 0;
|
|
521
|
+
this[offset] = value & 0xff;
|
|
522
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
523
|
+
this[offset + i] = (value / mul) & 0xff;
|
|
524
|
+
}
|
|
525
|
+
return offset + byteLength;
|
|
526
|
+
}
|
|
527
|
+
writeUIntBE(value, offset, byteLength, noAssert) {
|
|
528
|
+
value = Number(value);
|
|
529
|
+
offset = offset >>> 0;
|
|
530
|
+
byteLength = byteLength >>> 0;
|
|
531
|
+
if (!noAssert) {
|
|
532
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
533
|
+
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
534
|
+
}
|
|
535
|
+
let i = byteLength - 1;
|
|
536
|
+
let mul = 1;
|
|
537
|
+
this[offset + i] = value & 0xff;
|
|
538
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
539
|
+
this[offset + i] = (value / mul) & 0xff;
|
|
540
|
+
}
|
|
541
|
+
return offset + byteLength;
|
|
281
542
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
while (byteLength > 0 && (mul *= 0x100)) {
|
|
285
|
-
val += this[offset + --byteLength] * mul;
|
|
543
|
+
writeBigUInt64LE(value, offset = 0) {
|
|
544
|
+
return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'));
|
|
286
545
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
readBigUInt64LE(offset) {
|
|
290
|
-
offset = offset >>> 0;
|
|
291
|
-
validateNumber(offset, 'offset');
|
|
292
|
-
const first = this[offset];
|
|
293
|
-
const last = this[offset + 7];
|
|
294
|
-
if (first === undefined || last === undefined) {
|
|
295
|
-
boundsError(offset, this.length - 8);
|
|
296
|
-
}
|
|
297
|
-
const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24;
|
|
298
|
-
const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24;
|
|
299
|
-
return BigInt(lo) + (BigInt(hi) << BigInt(32));
|
|
300
|
-
}
|
|
301
|
-
readBigUInt64BE(offset) {
|
|
302
|
-
offset = offset >>> 0;
|
|
303
|
-
validateNumber(offset, 'offset');
|
|
304
|
-
const first = this[offset];
|
|
305
|
-
const last = this[offset + 7];
|
|
306
|
-
if (first === undefined || last === undefined) {
|
|
307
|
-
boundsError(offset, this.length - 8);
|
|
308
|
-
}
|
|
309
|
-
const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset];
|
|
310
|
-
const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last;
|
|
311
|
-
return (BigInt(hi) << BigInt(32)) + BigInt(lo);
|
|
312
|
-
}
|
|
313
|
-
readFloatLE(offset, noAssert) {
|
|
314
|
-
offset = offset >>> 0;
|
|
315
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
316
|
-
return ieee754.read(this, offset, true, 23, 4);
|
|
317
|
-
}
|
|
318
|
-
readFloatBE(offset, noAssert) {
|
|
319
|
-
offset = offset >>> 0;
|
|
320
|
-
if (!noAssert) checkOffset(offset, 4, this.length);
|
|
321
|
-
return ieee754.read(this, offset, false, 23, 4);
|
|
322
|
-
}
|
|
323
|
-
readDoubleLE(offset, noAssert) {
|
|
324
|
-
offset = offset >>> 0;
|
|
325
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
326
|
-
return ieee754.read(this, offset, true, 52, 8);
|
|
327
|
-
}
|
|
328
|
-
readDoubleBE(offset, noAssert) {
|
|
329
|
-
offset = offset >>> 0;
|
|
330
|
-
if (!noAssert) checkOffset(offset, 8, this.length);
|
|
331
|
-
return ieee754.read(this, offset, false, 52, 8);
|
|
332
|
-
}
|
|
333
|
-
writeUInt8(value, offset, noAssert) {
|
|
334
|
-
value = Number(value);
|
|
335
|
-
offset = offset >>> 0;
|
|
336
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
|
|
337
|
-
this[offset] = value & 0xff;
|
|
338
|
-
return offset + 1;
|
|
339
|
-
}
|
|
340
|
-
writeUInt16LE(value, offset, noAssert) {
|
|
341
|
-
value = Number(value);
|
|
342
|
-
offset = offset >>> 0;
|
|
343
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
344
|
-
this[offset] = value & 0xff;
|
|
345
|
-
this[offset + 1] = value >>> 8;
|
|
346
|
-
return offset + 2;
|
|
347
|
-
}
|
|
348
|
-
writeUInt16BE(value, offset, noAssert) {
|
|
349
|
-
value = Number(value);
|
|
350
|
-
offset = offset >>> 0;
|
|
351
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
|
|
352
|
-
this[offset] = value >>> 8;
|
|
353
|
-
this[offset + 1] = value & 0xff;
|
|
354
|
-
return offset + 2;
|
|
355
|
-
}
|
|
356
|
-
writeUInt32LE(value, offset, noAssert) {
|
|
357
|
-
value = Number(value);
|
|
358
|
-
offset = offset >>> 0;
|
|
359
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
360
|
-
this[offset + 3] = value >>> 24;
|
|
361
|
-
this[offset + 2] = value >>> 16;
|
|
362
|
-
this[offset + 1] = value >>> 8;
|
|
363
|
-
this[offset] = value & 0xff;
|
|
364
|
-
return offset + 4;
|
|
365
|
-
}
|
|
366
|
-
writeUInt32BE(value, offset, noAssert) {
|
|
367
|
-
value = Number(value);
|
|
368
|
-
offset = offset >>> 0;
|
|
369
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
|
|
370
|
-
this[offset] = value >>> 24;
|
|
371
|
-
this[offset + 1] = value >>> 16;
|
|
372
|
-
this[offset + 2] = value >>> 8;
|
|
373
|
-
this[offset + 3] = value & 0xff;
|
|
374
|
-
return offset + 4;
|
|
375
|
-
}
|
|
376
|
-
writeUIntLE(value, offset, byteLength, noAssert) {
|
|
377
|
-
value = Number(value);
|
|
378
|
-
offset = offset >>> 0;
|
|
379
|
-
byteLength = byteLength >>> 0;
|
|
380
|
-
if (!noAssert) {
|
|
381
|
-
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
|
382
|
-
checkInt(this, value, offset, byteLength, maxBytes, 0);
|
|
546
|
+
writeBigUInt64BE(value, offset = 0) {
|
|
547
|
+
return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt('0xffffffffffffffff'));
|
|
383
548
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
549
|
+
writeIntLE(value, offset, byteLength, noAssert) {
|
|
550
|
+
value = Number(value);
|
|
551
|
+
offset = offset >>> 0;
|
|
552
|
+
if (!noAssert) {
|
|
553
|
+
const limit = Math.pow(2, 8 * byteLength - 1);
|
|
554
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
555
|
+
}
|
|
556
|
+
let i = 0;
|
|
557
|
+
let mul = 1;
|
|
558
|
+
let sub = 0;
|
|
559
|
+
this[offset] = value & 0xff;
|
|
560
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
|
561
|
+
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
562
|
+
sub = 1;
|
|
563
|
+
}
|
|
564
|
+
this[offset + i] = (((value / mul) >> 0) - sub) & 0xff;
|
|
565
|
+
}
|
|
566
|
+
return offset + byteLength;
|
|
567
|
+
}
|
|
568
|
+
writeIntBE(value, offset, byteLength, noAssert) {
|
|
569
|
+
value = Number(value);
|
|
570
|
+
offset = offset >>> 0;
|
|
571
|
+
if (!noAssert) {
|
|
572
|
+
const limit = Math.pow(2, 8 * byteLength - 1);
|
|
573
|
+
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
574
|
+
}
|
|
575
|
+
let i = byteLength - 1;
|
|
576
|
+
let mul = 1;
|
|
577
|
+
let sub = 0;
|
|
578
|
+
this[offset + i] = value & 0xff;
|
|
579
|
+
while (--i >= 0 && (mul *= 0x100)) {
|
|
580
|
+
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
581
|
+
sub = 1;
|
|
582
|
+
}
|
|
583
|
+
this[offset + i] = (((value / mul) >> 0) - sub) & 0xff;
|
|
584
|
+
}
|
|
585
|
+
return offset + byteLength;
|
|
586
|
+
}
|
|
587
|
+
writeInt8(value, offset, noAssert) {
|
|
588
|
+
value = Number(value);
|
|
589
|
+
offset = offset >>> 0;
|
|
590
|
+
if (!noAssert)
|
|
591
|
+
checkInt(this, value, offset, 1, 0x7f, -0x80);
|
|
592
|
+
if (value < 0)
|
|
593
|
+
value = 0xff + value + 1;
|
|
594
|
+
this[offset] = value & 0xff;
|
|
595
|
+
return offset + 1;
|
|
596
|
+
}
|
|
597
|
+
writeInt16LE(value, offset, noAssert) {
|
|
598
|
+
value = Number(value);
|
|
599
|
+
offset = offset >>> 0;
|
|
600
|
+
if (!noAssert)
|
|
601
|
+
checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
602
|
+
this[offset] = value & 0xff;
|
|
603
|
+
this[offset + 1] = value >>> 8;
|
|
604
|
+
return offset + 2;
|
|
605
|
+
}
|
|
606
|
+
writeInt16BE(value, offset, noAssert) {
|
|
607
|
+
value = Number(value);
|
|
608
|
+
offset = offset >>> 0;
|
|
609
|
+
if (!noAssert)
|
|
610
|
+
checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
611
|
+
this[offset] = value >>> 8;
|
|
612
|
+
this[offset + 1] = value & 0xff;
|
|
613
|
+
return offset + 2;
|
|
614
|
+
}
|
|
615
|
+
writeInt32LE(value, offset, noAssert) {
|
|
616
|
+
value = Number(value);
|
|
617
|
+
offset = offset >>> 0;
|
|
618
|
+
if (!noAssert)
|
|
619
|
+
checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
620
|
+
this[offset] = value & 0xff;
|
|
621
|
+
this[offset + 1] = value >>> 8;
|
|
622
|
+
this[offset + 2] = value >>> 16;
|
|
623
|
+
this[offset + 3] = value >>> 24;
|
|
624
|
+
return offset + 4;
|
|
625
|
+
}
|
|
626
|
+
writeInt32BE(value, offset, noAssert) {
|
|
627
|
+
value = Number(value);
|
|
628
|
+
offset = offset >>> 0;
|
|
629
|
+
if (!noAssert)
|
|
630
|
+
checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
631
|
+
if (value < 0)
|
|
632
|
+
value = 0xffffffff + value + 1;
|
|
633
|
+
this[offset] = value >>> 24;
|
|
634
|
+
this[offset + 1] = value >>> 16;
|
|
635
|
+
this[offset + 2] = value >>> 8;
|
|
636
|
+
this[offset + 3] = value & 0xff;
|
|
637
|
+
return offset + 4;
|
|
638
|
+
}
|
|
639
|
+
writeBigInt64LE(value, offset = 0) {
|
|
640
|
+
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'));
|
|
641
|
+
}
|
|
642
|
+
writeBigInt64BE(value, offset = 0) {
|
|
643
|
+
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'));
|
|
644
|
+
}
|
|
645
|
+
writeFloatLE(value, offset, noAssert) {
|
|
646
|
+
return writeFloat(this, value, offset, true, noAssert);
|
|
647
|
+
}
|
|
648
|
+
writeFloatBE(value, offset, noAssert) {
|
|
649
|
+
return writeFloat(this, value, offset, false, noAssert);
|
|
650
|
+
}
|
|
651
|
+
writeDoubleLE(value, offset, noAssert) {
|
|
652
|
+
return writeDouble(this, value, offset, true, noAssert);
|
|
653
|
+
}
|
|
654
|
+
writeDoubleBE(value, offset, noAssert) {
|
|
655
|
+
return writeDouble(this, value, offset, false, noAssert);
|
|
656
|
+
}
|
|
657
|
+
write(string, offset, length, encoding) {
|
|
658
|
+
// Buffer#write(string)
|
|
659
|
+
if (offset === undefined) {
|
|
660
|
+
encoding = 'utf8';
|
|
661
|
+
length = this.length;
|
|
662
|
+
offset = 0;
|
|
663
|
+
// Buffer#write(string, encoding)
|
|
664
|
+
}
|
|
665
|
+
else if (length === undefined && typeof offset === 'string') {
|
|
666
|
+
encoding = offset;
|
|
667
|
+
length = this.length;
|
|
668
|
+
offset = 0;
|
|
669
|
+
// Buffer#write(string, offset[, length][, encoding])
|
|
670
|
+
}
|
|
671
|
+
else if (isFinite(offset)) {
|
|
672
|
+
offset = offset >>> 0;
|
|
673
|
+
if (isFinite(length)) {
|
|
674
|
+
length = length >>> 0;
|
|
675
|
+
if (encoding === undefined)
|
|
676
|
+
encoding = 'utf8';
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
encoding = length;
|
|
680
|
+
length = undefined;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
|
|
685
|
+
}
|
|
686
|
+
const remaining = this.length - offset;
|
|
687
|
+
if (length === undefined || length > remaining)
|
|
688
|
+
length = remaining;
|
|
689
|
+
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
|
|
690
|
+
throw new RangeError('Attempt to write outside buffer bounds');
|
|
691
|
+
}
|
|
692
|
+
if (!encoding)
|
|
693
|
+
encoding = 'utf8';
|
|
694
|
+
let loweredCase = false;
|
|
695
|
+
for (;;) {
|
|
696
|
+
switch (encoding) {
|
|
697
|
+
case 'hex':
|
|
698
|
+
return hexWrite(this, string, offset, length);
|
|
699
|
+
case 'utf8':
|
|
700
|
+
case 'utf-8':
|
|
701
|
+
return utf8Write(this, string, offset, length);
|
|
702
|
+
case 'ascii':
|
|
703
|
+
case 'latin1':
|
|
704
|
+
case 'binary':
|
|
705
|
+
return asciiWrite(this, string, offset, length);
|
|
706
|
+
case 'base64':
|
|
707
|
+
// Warning: maxLength not taken into account in base64Write
|
|
708
|
+
return base64Write(this, string, offset, length);
|
|
709
|
+
case 'ucs2':
|
|
710
|
+
case 'ucs-2':
|
|
711
|
+
case 'utf16le':
|
|
712
|
+
case 'utf-16le':
|
|
713
|
+
return ucs2Write(this, string, offset, length);
|
|
714
|
+
default:
|
|
715
|
+
if (loweredCase)
|
|
716
|
+
throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
717
|
+
encoding = `${encoding}`.toLowerCase();
|
|
718
|
+
loweredCase = true;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
389
721
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
722
|
+
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
|
|
723
|
+
copy(target, targetStart, start, end) {
|
|
724
|
+
if (!Buffer.isBuffer(target))
|
|
725
|
+
throw new TypeError('argument should be a Buffer');
|
|
726
|
+
if (!start)
|
|
727
|
+
start = 0;
|
|
728
|
+
if (!end && end !== 0)
|
|
729
|
+
end = this.length;
|
|
730
|
+
if (targetStart >= target.length)
|
|
731
|
+
targetStart = target.length;
|
|
732
|
+
if (!targetStart)
|
|
733
|
+
targetStart = 0;
|
|
734
|
+
if (end > 0 && end < start)
|
|
735
|
+
end = start;
|
|
736
|
+
// Copy 0 bytes; we're done
|
|
737
|
+
if (end === start)
|
|
738
|
+
return 0;
|
|
739
|
+
if (target.length === 0 || this.length === 0)
|
|
740
|
+
return 0;
|
|
741
|
+
// Fatal error conditions
|
|
742
|
+
if (targetStart < 0) {
|
|
743
|
+
throw new RangeError('targetStart out of bounds');
|
|
744
|
+
}
|
|
745
|
+
if (start < 0 || start >= this.length)
|
|
746
|
+
throw new RangeError('Index out of range');
|
|
747
|
+
if (end < 0)
|
|
748
|
+
throw new RangeError('sourceEnd out of bounds');
|
|
749
|
+
// Are we oob?
|
|
750
|
+
if (end > this.length)
|
|
751
|
+
end = this.length;
|
|
752
|
+
if (target.length - targetStart < end - start) {
|
|
753
|
+
end = target.length - targetStart + start;
|
|
754
|
+
}
|
|
755
|
+
const len = end - start;
|
|
756
|
+
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
757
|
+
// Use built-in when available, missing from IE11
|
|
758
|
+
this.copyWithin(targetStart, start, end);
|
|
759
|
+
}
|
|
760
|
+
else {
|
|
761
|
+
Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
|
|
762
|
+
}
|
|
763
|
+
return len;
|
|
764
|
+
}
|
|
765
|
+
// Usage:
|
|
766
|
+
// buffer.fill(number[, offset[, end]])
|
|
767
|
+
// buffer.fill(buffer[, offset[, end]])
|
|
768
|
+
// buffer.fill(string[, offset[, end]][, encoding])
|
|
769
|
+
fill(val, start, end, encoding) {
|
|
770
|
+
// Handle string cases:
|
|
771
|
+
if (typeof val === 'string') {
|
|
772
|
+
if (typeof start === 'string') {
|
|
773
|
+
encoding = start;
|
|
774
|
+
start = 0;
|
|
775
|
+
end = this.length;
|
|
776
|
+
}
|
|
777
|
+
else if (typeof end === 'string') {
|
|
778
|
+
encoding = end;
|
|
779
|
+
end = this.length;
|
|
780
|
+
}
|
|
781
|
+
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
782
|
+
throw new TypeError('encoding must be a string');
|
|
783
|
+
}
|
|
784
|
+
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
785
|
+
throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
786
|
+
}
|
|
787
|
+
if (val.length === 1) {
|
|
788
|
+
const code = val.charCodeAt(0);
|
|
789
|
+
if ((encoding === 'utf8' && code < 128) || encoding === 'latin1') {
|
|
790
|
+
// Fast path: If `val` fits into a single byte, use that numeric value.
|
|
791
|
+
val = code;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
else if (typeof val === 'number') {
|
|
796
|
+
val = val & 255;
|
|
797
|
+
}
|
|
798
|
+
else if (typeof val === 'boolean') {
|
|
799
|
+
val = Number(val);
|
|
800
|
+
}
|
|
801
|
+
// Invalid ranges are not set to a default, so can range check early.
|
|
802
|
+
if (start < 0 || this.length < start || this.length < end) {
|
|
803
|
+
throw new RangeError('Out of range index');
|
|
804
|
+
}
|
|
805
|
+
if (end <= start) {
|
|
806
|
+
return this;
|
|
807
|
+
}
|
|
808
|
+
start = start >>> 0;
|
|
809
|
+
end = end === undefined ? this.length : end >>> 0;
|
|
810
|
+
if (!val)
|
|
811
|
+
val = 0;
|
|
812
|
+
let i;
|
|
813
|
+
if (typeof val === 'number') {
|
|
814
|
+
for (i = start; i < end; ++i) {
|
|
815
|
+
this[i] = val;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
|
|
820
|
+
const len = bytes.length;
|
|
821
|
+
if (len === 0) {
|
|
822
|
+
throw new TypeError(`The value "${val}" is invalid for argument "value"`);
|
|
823
|
+
}
|
|
824
|
+
for (i = 0; i < end - start; ++i) {
|
|
825
|
+
this[i + start] = bytes[i % len];
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return this;
|
|
829
|
+
}
|
|
830
|
+
swap16() {
|
|
831
|
+
const len = this.length;
|
|
832
|
+
if (len % 2 !== 0) {
|
|
833
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits');
|
|
834
|
+
}
|
|
835
|
+
for (let i = 0; i < len; i += 2) {
|
|
836
|
+
swap(this, i, i + 1);
|
|
837
|
+
}
|
|
838
|
+
return this;
|
|
839
|
+
}
|
|
840
|
+
swap32() {
|
|
841
|
+
const len = this.length;
|
|
842
|
+
if (len % 4 !== 0) {
|
|
843
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits');
|
|
844
|
+
}
|
|
845
|
+
for (let i = 0; i < len; i += 4) {
|
|
846
|
+
swap(this, i, i + 3);
|
|
847
|
+
swap(this, i + 1, i + 2);
|
|
848
|
+
}
|
|
849
|
+
return this;
|
|
850
|
+
}
|
|
851
|
+
swap64() {
|
|
852
|
+
const len = this.length;
|
|
853
|
+
if (len % 8 !== 0) {
|
|
854
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits');
|
|
855
|
+
}
|
|
856
|
+
for (let i = 0; i < len; i += 8) {
|
|
857
|
+
swap(this, i, i + 7);
|
|
858
|
+
swap(this, i + 1, i + 6);
|
|
859
|
+
swap(this, i + 2, i + 5);
|
|
860
|
+
swap(this, i + 3, i + 4);
|
|
861
|
+
}
|
|
862
|
+
return this;
|
|
863
|
+
}
|
|
864
|
+
toString(encoding, start, end) {
|
|
865
|
+
const length = this.length;
|
|
866
|
+
if (length === 0)
|
|
867
|
+
return '';
|
|
868
|
+
if (arguments.length === 0)
|
|
869
|
+
return utf8Slice(this, 0, length);
|
|
870
|
+
return this._slowToString(...arguments);
|
|
871
|
+
}
|
|
872
|
+
// toLocaleString(b) {
|
|
873
|
+
// if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
|
|
874
|
+
// if (this === b) return true;
|
|
875
|
+
// return Buffer.compare(this, b) === 0;
|
|
876
|
+
// }
|
|
877
|
+
inspect() {
|
|
878
|
+
let str = '';
|
|
879
|
+
const max = INSPECT_MAX_BYTES;
|
|
880
|
+
str = this.toString('hex', 0, max)
|
|
881
|
+
.replace(/(.{2})/g, '$1 ')
|
|
882
|
+
.trim();
|
|
883
|
+
if (this.length > max)
|
|
884
|
+
str += ' ... ';
|
|
885
|
+
return `<Buffer ${str}>`;
|
|
886
|
+
}
|
|
887
|
+
// if (customInspectSymbol) {
|
|
888
|
+
// Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
|
|
889
|
+
// }
|
|
890
|
+
// }
|
|
891
|
+
equals(b) {
|
|
892
|
+
if (!Buffer.isBuffer(b))
|
|
893
|
+
throw new TypeError('Argument must be a Buffer');
|
|
894
|
+
if (this === b)
|
|
895
|
+
return true;
|
|
896
|
+
return Buffer.compare(this, b) === 0;
|
|
897
|
+
}
|
|
898
|
+
compare(target, start, end, thisStart, thisEnd) {
|
|
899
|
+
if (!Buffer.isBuffer(target) && isInstance(target, Uint8Array)) {
|
|
900
|
+
target = Buffer.from(target, target.offset, target.byteLength);
|
|
901
|
+
}
|
|
902
|
+
if (!Buffer.isBuffer(target)) {
|
|
903
|
+
throw new TypeError(`${'The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type '}${typeof target}`);
|
|
904
|
+
}
|
|
905
|
+
if (start === undefined) {
|
|
906
|
+
start = 0;
|
|
907
|
+
}
|
|
908
|
+
if (end === undefined) {
|
|
909
|
+
end = target ? target.length : 0;
|
|
910
|
+
}
|
|
911
|
+
if (thisStart === undefined) {
|
|
912
|
+
thisStart = 0;
|
|
913
|
+
}
|
|
914
|
+
if (thisEnd === undefined) {
|
|
915
|
+
thisEnd = this.length;
|
|
916
|
+
}
|
|
917
|
+
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
918
|
+
throw new RangeError('out of range index');
|
|
919
|
+
}
|
|
920
|
+
if (thisStart >= thisEnd && start >= end) {
|
|
921
|
+
return 0;
|
|
922
|
+
}
|
|
923
|
+
if (thisStart >= thisEnd) {
|
|
924
|
+
return -1;
|
|
925
|
+
}
|
|
926
|
+
if (start >= end) {
|
|
927
|
+
return 1;
|
|
928
|
+
}
|
|
929
|
+
start >>>= 0;
|
|
930
|
+
end >>>= 0;
|
|
931
|
+
thisStart >>>= 0;
|
|
932
|
+
thisEnd >>>= 0;
|
|
933
|
+
if (this === target)
|
|
934
|
+
return 0;
|
|
935
|
+
let x = thisEnd - thisStart;
|
|
936
|
+
let y = end - start;
|
|
937
|
+
const len = Math.min(x, y);
|
|
938
|
+
const thisCopy = this.slice(thisStart, thisEnd);
|
|
939
|
+
const targetCopy = target.slice(start, end);
|
|
940
|
+
for (let i = 0; i < len; ++i) {
|
|
941
|
+
if (thisCopy[i] !== targetCopy[i]) {
|
|
942
|
+
x = thisCopy[i];
|
|
943
|
+
y = targetCopy[i];
|
|
944
|
+
break;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
if (x < y)
|
|
948
|
+
return -1;
|
|
949
|
+
if (y < x)
|
|
950
|
+
return 1;
|
|
951
|
+
return 0;
|
|
952
|
+
}
|
|
953
|
+
toJSON() {
|
|
954
|
+
return {
|
|
955
|
+
type: 'Buffer',
|
|
956
|
+
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
slice(start, end) {
|
|
960
|
+
const len = this.length;
|
|
961
|
+
start = ~~start;
|
|
962
|
+
end = end === undefined ? len : ~~end;
|
|
963
|
+
if (start < 0) {
|
|
964
|
+
start += len;
|
|
965
|
+
if (start < 0)
|
|
966
|
+
start = 0;
|
|
967
|
+
}
|
|
968
|
+
else if (start > len) {
|
|
969
|
+
start = len;
|
|
970
|
+
}
|
|
971
|
+
if (end < 0) {
|
|
972
|
+
end += len;
|
|
973
|
+
if (end < 0)
|
|
974
|
+
end = 0;
|
|
975
|
+
}
|
|
976
|
+
else if (end > len) {
|
|
977
|
+
end = len;
|
|
978
|
+
}
|
|
979
|
+
if (end < start)
|
|
980
|
+
end = start;
|
|
981
|
+
const newBuf = this.subarray(start, end);
|
|
982
|
+
// Return an augmented `Uint8Array` instance
|
|
983
|
+
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
984
|
+
return newBuf;
|
|
985
|
+
}
|
|
986
|
+
// Typo support?
|
|
987
|
+
// readUint8(offset: number, noAssert?: boolean): number {
|
|
988
|
+
// return this.readUInt8(...arguments);
|
|
989
|
+
// }
|
|
990
|
+
// readUint16LE(offset: number, noAssert?: boolean): number {
|
|
991
|
+
// return this.readUInt16LE(...arguments);
|
|
992
|
+
// }
|
|
993
|
+
// readUint16BE(offset: number, noAssert?: boolean): number {
|
|
994
|
+
// return this.readUInt16BE(...arguments);
|
|
995
|
+
// }
|
|
996
|
+
// readUint32LE(offset: number, noAssert?: boolean): number {
|
|
997
|
+
// return this.readUInt32LE(...arguments);
|
|
998
|
+
// }
|
|
999
|
+
// readUint32BE(offset: number, noAssert?: boolean): number {
|
|
1000
|
+
// return this.readUInt32BE(...arguments);
|
|
1001
|
+
// }
|
|
1002
|
+
// writeUint8() {
|
|
1003
|
+
// return this.writeUInt8(...arguments);
|
|
1004
|
+
// }
|
|
1005
|
+
// writeUint16LE
|
|
1006
|
+
// writeUint16LE
|
|
1007
|
+
// writeUint32LE = Buffer.prototype.
|
|
1008
|
+
// Buffer.prototype.writeUint32BE
|
|
1009
|
+
_slowToString(encoding, start, end) {
|
|
1010
|
+
let loweredCase = false;
|
|
1011
|
+
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
|
|
1012
|
+
// property of a typed array.
|
|
1013
|
+
// This behaves neither like String nor Uint8Array in that we set start/end
|
|
1014
|
+
// to their upper/lower bounds if the value passed is out of range.
|
|
1015
|
+
// undefined is handled specially as per ECMA-262 6th Edition,
|
|
1016
|
+
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
|
|
1017
|
+
if (start === undefined || start < 0) {
|
|
1018
|
+
start = 0;
|
|
1019
|
+
}
|
|
1020
|
+
// Return early if start > this.length. Done here to prevent potential uint32
|
|
1021
|
+
// coercion fail below.
|
|
1022
|
+
if (start > this.length) {
|
|
1023
|
+
return '';
|
|
1024
|
+
}
|
|
1025
|
+
if (end === undefined || end > this.length) {
|
|
1026
|
+
end = this.length;
|
|
1027
|
+
}
|
|
1028
|
+
if (end <= 0) {
|
|
1029
|
+
return '';
|
|
1030
|
+
}
|
|
1031
|
+
// Force coercion to uint32. This will also coerce falsey/NaN values to 0.
|
|
1032
|
+
end >>>= 0;
|
|
1033
|
+
start >>>= 0;
|
|
1034
|
+
if (end <= start) {
|
|
1035
|
+
return '';
|
|
1036
|
+
}
|
|
1037
|
+
if (!encoding)
|
|
1038
|
+
encoding = 'utf8';
|
|
1039
|
+
while (true) {
|
|
1040
|
+
switch (encoding) {
|
|
1041
|
+
case 'hex':
|
|
1042
|
+
return hexSlice(this, start, end);
|
|
1043
|
+
case 'utf8':
|
|
1044
|
+
case 'utf-8':
|
|
1045
|
+
return utf8Slice(this, start, end);
|
|
1046
|
+
case 'ascii':
|
|
1047
|
+
return asciiSlice(this, start, end);
|
|
1048
|
+
case 'latin1':
|
|
1049
|
+
case 'binary':
|
|
1050
|
+
return latin1Slice(this, start, end);
|
|
1051
|
+
case 'base64':
|
|
1052
|
+
return base64Slice(this, start, end);
|
|
1053
|
+
case 'ucs2':
|
|
1054
|
+
case 'ucs-2':
|
|
1055
|
+
case 'utf16le':
|
|
1056
|
+
case 'utf-16le':
|
|
1057
|
+
return utf16leSlice(this, start, end);
|
|
1058
|
+
default:
|
|
1059
|
+
if (loweredCase)
|
|
1060
|
+
throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
1061
|
+
encoding = `${encoding}`.toLowerCase();
|
|
1062
|
+
loweredCase = true;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
422
1065
|
}
|
|
423
|
-
let i = 0;
|
|
424
|
-
let mul = 1;
|
|
425
|
-
let sub = 0;
|
|
426
|
-
this[offset] = value & 0xff;
|
|
427
|
-
while (++i < byteLength && (mul *= 0x100)) {
|
|
428
|
-
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
429
|
-
sub = 1;
|
|
430
|
-
}
|
|
431
|
-
this[offset + i] = (value / mul >> 0) - sub & 0xff;
|
|
432
|
-
}
|
|
433
|
-
return offset + byteLength;
|
|
434
|
-
}
|
|
435
|
-
writeIntBE(value, offset, byteLength, noAssert) {
|
|
436
|
-
value = Number(value);
|
|
437
|
-
offset = offset >>> 0;
|
|
438
|
-
if (!noAssert) {
|
|
439
|
-
const limit = Math.pow(2, 8 * byteLength - 1);
|
|
440
|
-
checkInt(this, value, offset, byteLength, limit - 1, -limit);
|
|
441
|
-
}
|
|
442
|
-
let i = byteLength - 1;
|
|
443
|
-
let mul = 1;
|
|
444
|
-
let sub = 0;
|
|
445
|
-
this[offset + i] = value & 0xff;
|
|
446
|
-
while (--i >= 0 && (mul *= 0x100)) {
|
|
447
|
-
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
448
|
-
sub = 1;
|
|
449
|
-
}
|
|
450
|
-
this[offset + i] = (value / mul >> 0) - sub & 0xff;
|
|
451
|
-
}
|
|
452
|
-
return offset + byteLength;
|
|
453
|
-
}
|
|
454
|
-
writeInt8(value, offset, noAssert) {
|
|
455
|
-
value = Number(value);
|
|
456
|
-
offset = offset >>> 0;
|
|
457
|
-
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
|
|
458
|
-
if (value < 0) value = 0xff + value + 1;
|
|
459
|
-
this[offset] = value & 0xff;
|
|
460
|
-
return offset + 1;
|
|
461
|
-
}
|
|
462
|
-
writeInt16LE(value, offset, noAssert) {
|
|
463
|
-
value = Number(value);
|
|
464
|
-
offset = offset >>> 0;
|
|
465
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
466
|
-
this[offset] = value & 0xff;
|
|
467
|
-
this[offset + 1] = value >>> 8;
|
|
468
|
-
return offset + 2;
|
|
469
|
-
}
|
|
470
|
-
writeInt16BE(value, offset, noAssert) {
|
|
471
|
-
value = Number(value);
|
|
472
|
-
offset = offset >>> 0;
|
|
473
|
-
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
|
|
474
|
-
this[offset] = value >>> 8;
|
|
475
|
-
this[offset + 1] = value & 0xff;
|
|
476
|
-
return offset + 2;
|
|
477
|
-
}
|
|
478
|
-
writeInt32LE(value, offset, noAssert) {
|
|
479
|
-
value = Number(value);
|
|
480
|
-
offset = offset >>> 0;
|
|
481
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
482
|
-
this[offset] = value & 0xff;
|
|
483
|
-
this[offset + 1] = value >>> 8;
|
|
484
|
-
this[offset + 2] = value >>> 16;
|
|
485
|
-
this[offset + 3] = value >>> 24;
|
|
486
|
-
return offset + 4;
|
|
487
|
-
}
|
|
488
|
-
writeInt32BE(value, offset, noAssert) {
|
|
489
|
-
value = Number(value);
|
|
490
|
-
offset = offset >>> 0;
|
|
491
|
-
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
|
|
492
|
-
if (value < 0) value = 0xffffffff + value + 1;
|
|
493
|
-
this[offset] = value >>> 24;
|
|
494
|
-
this[offset + 1] = value >>> 16;
|
|
495
|
-
this[offset + 2] = value >>> 8;
|
|
496
|
-
this[offset + 3] = value & 0xff;
|
|
497
|
-
return offset + 4;
|
|
498
|
-
}
|
|
499
|
-
writeBigInt64LE(value) {
|
|
500
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
501
|
-
return wrtBigUInt64LE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'));
|
|
502
|
-
}
|
|
503
|
-
writeBigInt64BE(value) {
|
|
504
|
-
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
505
|
-
return wrtBigUInt64BE(this, value, offset, -BigInt('0x8000000000000000'), BigInt('0x7fffffffffffffff'));
|
|
506
|
-
}
|
|
507
|
-
writeFloatLE(value, offset, noAssert) {
|
|
508
|
-
return writeFloat(this, value, offset, true, noAssert);
|
|
509
|
-
}
|
|
510
|
-
writeFloatBE(value, offset, noAssert) {
|
|
511
|
-
return writeFloat(this, value, offset, false, noAssert);
|
|
512
|
-
}
|
|
513
|
-
writeDoubleLE(value, offset, noAssert) {
|
|
514
|
-
return writeDouble(this, value, offset, true, noAssert);
|
|
515
|
-
}
|
|
516
|
-
writeDoubleBE(value, offset, noAssert) {
|
|
517
|
-
return writeDouble(this, value, offset, false, noAssert);
|
|
518
|
-
}
|
|
519
|
-
write(string, offset, length, encoding) {
|
|
520
|
-
if (offset === undefined) {
|
|
521
|
-
encoding = 'utf8';
|
|
522
|
-
length = this.length;
|
|
523
|
-
offset = 0;
|
|
524
|
-
} else if (length === undefined && typeof offset === 'string') {
|
|
525
|
-
encoding = offset;
|
|
526
|
-
length = this.length;
|
|
527
|
-
offset = 0;
|
|
528
|
-
} else if (isFinite(offset)) {
|
|
529
|
-
offset = offset >>> 0;
|
|
530
|
-
if (isFinite(length)) {
|
|
531
|
-
length = length >>> 0;
|
|
532
|
-
if (encoding === undefined) encoding = 'utf8';
|
|
533
|
-
} else {
|
|
534
|
-
encoding = length;
|
|
535
|
-
length = undefined;
|
|
536
|
-
}
|
|
537
|
-
} else {
|
|
538
|
-
throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
|
|
539
|
-
}
|
|
540
|
-
const remaining = this.length - offset;
|
|
541
|
-
if (length === undefined || length > remaining) length = remaining;
|
|
542
|
-
if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
|
|
543
|
-
throw new RangeError('Attempt to write outside buffer bounds');
|
|
544
|
-
}
|
|
545
|
-
if (!encoding) encoding = 'utf8';
|
|
546
|
-
let loweredCase = false;
|
|
547
|
-
for (;;) {
|
|
548
|
-
switch (encoding) {
|
|
549
|
-
case 'hex':
|
|
550
|
-
return hexWrite(this, string, offset, length);
|
|
551
|
-
case 'utf8':
|
|
552
|
-
case 'utf-8':
|
|
553
|
-
return utf8Write(this, string, offset, length);
|
|
554
|
-
case 'ascii':
|
|
555
|
-
case 'latin1':
|
|
556
|
-
case 'binary':
|
|
557
|
-
return asciiWrite(this, string, offset, length);
|
|
558
|
-
case 'base64':
|
|
559
|
-
return base64Write(this, string, offset, length);
|
|
560
|
-
case 'ucs2':
|
|
561
|
-
case 'ucs-2':
|
|
562
|
-
case 'utf16le':
|
|
563
|
-
case 'utf-16le':
|
|
564
|
-
return ucs2Write(this, string, offset, length);
|
|
565
|
-
default:
|
|
566
|
-
if (loweredCase) throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
567
|
-
encoding = `${encoding}`.toLowerCase();
|
|
568
|
-
loweredCase = true;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
copy(target, targetStart, start, end) {
|
|
573
|
-
if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer');
|
|
574
|
-
if (!start) start = 0;
|
|
575
|
-
if (!end && end !== 0) end = this.length;
|
|
576
|
-
if (targetStart >= target.length) targetStart = target.length;
|
|
577
|
-
if (!targetStart) targetStart = 0;
|
|
578
|
-
if (end > 0 && end < start) end = start;
|
|
579
|
-
if (end === start) return 0;
|
|
580
|
-
if (target.length === 0 || this.length === 0) return 0;
|
|
581
|
-
if (targetStart < 0) {
|
|
582
|
-
throw new RangeError('targetStart out of bounds');
|
|
583
|
-
}
|
|
584
|
-
if (start < 0 || start >= this.length) throw new RangeError('Index out of range');
|
|
585
|
-
if (end < 0) throw new RangeError('sourceEnd out of bounds');
|
|
586
|
-
if (end > this.length) end = this.length;
|
|
587
|
-
if (target.length - targetStart < end - start) {
|
|
588
|
-
end = target.length - targetStart + start;
|
|
589
|
-
}
|
|
590
|
-
const len = end - start;
|
|
591
|
-
if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
|
|
592
|
-
this.copyWithin(targetStart, start, end);
|
|
593
|
-
} else {
|
|
594
|
-
Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
|
|
595
|
-
}
|
|
596
|
-
return len;
|
|
597
|
-
}
|
|
598
|
-
fill(val, start, end, encoding) {
|
|
599
|
-
if (typeof val === 'string') {
|
|
600
|
-
if (typeof start === 'string') {
|
|
601
|
-
encoding = start;
|
|
602
|
-
start = 0;
|
|
603
|
-
end = this.length;
|
|
604
|
-
} else if (typeof end === 'string') {
|
|
605
|
-
encoding = end;
|
|
606
|
-
end = this.length;
|
|
607
|
-
}
|
|
608
|
-
if (encoding !== undefined && typeof encoding !== 'string') {
|
|
609
|
-
throw new TypeError('encoding must be a string');
|
|
610
|
-
}
|
|
611
|
-
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
|
612
|
-
throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
613
|
-
}
|
|
614
|
-
if (val.length === 1) {
|
|
615
|
-
const code = val.charCodeAt(0);
|
|
616
|
-
if (encoding === 'utf8' && code < 128 || encoding === 'latin1') {
|
|
617
|
-
val = code;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
} else if (typeof val === 'number') {
|
|
621
|
-
val = val & 255;
|
|
622
|
-
} else if (typeof val === 'boolean') {
|
|
623
|
-
val = Number(val);
|
|
624
|
-
}
|
|
625
|
-
if (start < 0 || this.length < start || this.length < end) {
|
|
626
|
-
throw new RangeError('Out of range index');
|
|
627
|
-
}
|
|
628
|
-
if (end <= start) {
|
|
629
|
-
return this;
|
|
630
|
-
}
|
|
631
|
-
start = start >>> 0;
|
|
632
|
-
end = end === undefined ? this.length : end >>> 0;
|
|
633
|
-
if (!val) val = 0;
|
|
634
|
-
let i;
|
|
635
|
-
if (typeof val === 'number') {
|
|
636
|
-
for (i = start; i < end; ++i) {
|
|
637
|
-
this[i] = val;
|
|
638
|
-
}
|
|
639
|
-
} else {
|
|
640
|
-
const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
|
|
641
|
-
const len = bytes.length;
|
|
642
|
-
if (len === 0) {
|
|
643
|
-
throw new TypeError(`The value "${val}" is invalid for argument "value"`);
|
|
644
|
-
}
|
|
645
|
-
for (i = 0; i < end - start; ++i) {
|
|
646
|
-
this[i + start] = bytes[i % len];
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
return this;
|
|
650
|
-
}
|
|
651
|
-
swap16() {
|
|
652
|
-
const len = this.length;
|
|
653
|
-
if (len % 2 !== 0) {
|
|
654
|
-
throw new RangeError('Buffer size must be a multiple of 16-bits');
|
|
655
|
-
}
|
|
656
|
-
for (let i = 0; i < len; i += 2) {
|
|
657
|
-
swap(this, i, i + 1);
|
|
658
|
-
}
|
|
659
|
-
return this;
|
|
660
|
-
}
|
|
661
|
-
swap32() {
|
|
662
|
-
const len = this.length;
|
|
663
|
-
if (len % 4 !== 0) {
|
|
664
|
-
throw new RangeError('Buffer size must be a multiple of 32-bits');
|
|
665
|
-
}
|
|
666
|
-
for (let i = 0; i < len; i += 4) {
|
|
667
|
-
swap(this, i, i + 3);
|
|
668
|
-
swap(this, i + 1, i + 2);
|
|
669
|
-
}
|
|
670
|
-
return this;
|
|
671
|
-
}
|
|
672
|
-
swap64() {
|
|
673
|
-
const len = this.length;
|
|
674
|
-
if (len % 8 !== 0) {
|
|
675
|
-
throw new RangeError('Buffer size must be a multiple of 64-bits');
|
|
676
|
-
}
|
|
677
|
-
for (let i = 0; i < len; i += 8) {
|
|
678
|
-
swap(this, i, i + 7);
|
|
679
|
-
swap(this, i + 1, i + 6);
|
|
680
|
-
swap(this, i + 2, i + 5);
|
|
681
|
-
swap(this, i + 3, i + 4);
|
|
682
|
-
}
|
|
683
|
-
return this;
|
|
684
|
-
}
|
|
685
|
-
toString(encoding, start, end) {
|
|
686
|
-
const length = this.length;
|
|
687
|
-
if (length === 0) return '';
|
|
688
|
-
if (arguments.length === 0) return utf8Slice(this, 0, length);
|
|
689
|
-
return this._slowToString(...arguments);
|
|
690
|
-
}
|
|
691
|
-
inspect() {
|
|
692
|
-
let str = '';
|
|
693
|
-
const max = INSPECT_MAX_BYTES;
|
|
694
|
-
str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
|
|
695
|
-
if (this.length > max) str += ' ... ';
|
|
696
|
-
return `<Buffer ${str}>`;
|
|
697
|
-
}
|
|
698
|
-
equals(b) {
|
|
699
|
-
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
|
|
700
|
-
if (this === b) return true;
|
|
701
|
-
return Buffer.compare(this, b) === 0;
|
|
702
|
-
}
|
|
703
|
-
compare(target, start, end, thisStart, thisEnd) {
|
|
704
|
-
if (!Buffer.isBuffer(target) && isInstance(target, Uint8Array)) {
|
|
705
|
-
target = Buffer.from(target, target.offset, target.byteLength);
|
|
706
|
-
}
|
|
707
|
-
if (!Buffer.isBuffer(target)) {
|
|
708
|
-
throw new TypeError(`${'The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type '}${typeof target}`);
|
|
709
|
-
}
|
|
710
|
-
if (start === undefined) {
|
|
711
|
-
start = 0;
|
|
712
|
-
}
|
|
713
|
-
if (end === undefined) {
|
|
714
|
-
end = target ? target.length : 0;
|
|
715
|
-
}
|
|
716
|
-
if (thisStart === undefined) {
|
|
717
|
-
thisStart = 0;
|
|
718
|
-
}
|
|
719
|
-
if (thisEnd === undefined) {
|
|
720
|
-
thisEnd = this.length;
|
|
721
|
-
}
|
|
722
|
-
if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
|
|
723
|
-
throw new RangeError('out of range index');
|
|
724
|
-
}
|
|
725
|
-
if (thisStart >= thisEnd && start >= end) {
|
|
726
|
-
return 0;
|
|
727
|
-
}
|
|
728
|
-
if (thisStart >= thisEnd) {
|
|
729
|
-
return -1;
|
|
730
|
-
}
|
|
731
|
-
if (start >= end) {
|
|
732
|
-
return 1;
|
|
733
|
-
}
|
|
734
|
-
start >>>= 0;
|
|
735
|
-
end >>>= 0;
|
|
736
|
-
thisStart >>>= 0;
|
|
737
|
-
thisEnd >>>= 0;
|
|
738
|
-
if (this === target) return 0;
|
|
739
|
-
let x = thisEnd - thisStart;
|
|
740
|
-
let y = end - start;
|
|
741
|
-
const len = Math.min(x, y);
|
|
742
|
-
const thisCopy = this.slice(thisStart, thisEnd);
|
|
743
|
-
const targetCopy = target.slice(start, end);
|
|
744
|
-
for (let i = 0; i < len; ++i) {
|
|
745
|
-
if (thisCopy[i] !== targetCopy[i]) {
|
|
746
|
-
x = thisCopy[i];
|
|
747
|
-
y = targetCopy[i];
|
|
748
|
-
break;
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
if (x < y) return -1;
|
|
752
|
-
if (y < x) return 1;
|
|
753
|
-
return 0;
|
|
754
|
-
}
|
|
755
|
-
toJSON() {
|
|
756
|
-
return {
|
|
757
|
-
type: 'Buffer',
|
|
758
|
-
data: Array.prototype.slice.call(this._arr || this, 0)
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
slice(start, end) {
|
|
762
|
-
const len = this.length;
|
|
763
|
-
start = ~~start;
|
|
764
|
-
end = end === undefined ? len : ~~end;
|
|
765
|
-
if (start < 0) {
|
|
766
|
-
start += len;
|
|
767
|
-
if (start < 0) start = 0;
|
|
768
|
-
} else if (start > len) {
|
|
769
|
-
start = len;
|
|
770
|
-
}
|
|
771
|
-
if (end < 0) {
|
|
772
|
-
end += len;
|
|
773
|
-
if (end < 0) end = 0;
|
|
774
|
-
} else if (end > len) {
|
|
775
|
-
end = len;
|
|
776
|
-
}
|
|
777
|
-
if (end < start) end = start;
|
|
778
|
-
const newBuf = this.subarray(start, end);
|
|
779
|
-
Object.setPrototypeOf(newBuf, Buffer.prototype);
|
|
780
|
-
return newBuf;
|
|
781
|
-
}
|
|
782
|
-
_slowToString(encoding, start, end) {
|
|
783
|
-
let loweredCase = false;
|
|
784
|
-
if (start === undefined || start < 0) {
|
|
785
|
-
start = 0;
|
|
786
|
-
}
|
|
787
|
-
if (start > this.length) {
|
|
788
|
-
return '';
|
|
789
|
-
}
|
|
790
|
-
if (end === undefined || end > this.length) {
|
|
791
|
-
end = this.length;
|
|
792
|
-
}
|
|
793
|
-
if (end <= 0) {
|
|
794
|
-
return '';
|
|
795
|
-
}
|
|
796
|
-
end >>>= 0;
|
|
797
|
-
start >>>= 0;
|
|
798
|
-
if (end <= start) {
|
|
799
|
-
return '';
|
|
800
|
-
}
|
|
801
|
-
if (!encoding) encoding = 'utf8';
|
|
802
|
-
while (true) {
|
|
803
|
-
switch (encoding) {
|
|
804
|
-
case 'hex':
|
|
805
|
-
return hexSlice(this, start, end);
|
|
806
|
-
case 'utf8':
|
|
807
|
-
case 'utf-8':
|
|
808
|
-
return utf8Slice(this, start, end);
|
|
809
|
-
case 'ascii':
|
|
810
|
-
return asciiSlice(this, start, end);
|
|
811
|
-
case 'latin1':
|
|
812
|
-
case 'binary':
|
|
813
|
-
return latin1Slice(this, start, end);
|
|
814
|
-
case 'base64':
|
|
815
|
-
return base64Slice(this, start, end);
|
|
816
|
-
case 'ucs2':
|
|
817
|
-
case 'ucs-2':
|
|
818
|
-
case 'utf16le':
|
|
819
|
-
case 'utf-16le':
|
|
820
|
-
return utf16leSlice(this, start, end);
|
|
821
|
-
default:
|
|
822
|
-
if (loweredCase) throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
823
|
-
encoding = `${encoding}`.toLowerCase();
|
|
824
|
-
loweredCase = true;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
1066
|
}
|
|
829
|
-
Buffer.poolSize = 8192;
|
|
1067
|
+
Buffer.poolSize = 8192; // not used by this implementation
|
|
830
1068
|
function checkInt(buf, value, offset, ext, max, min) {
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1069
|
+
if (!Buffer.isBuffer(buf))
|
|
1070
|
+
throw new TypeError('"buffer" argument must be a Buffer instance');
|
|
1071
|
+
if (value > max || value < min)
|
|
1072
|
+
throw new RangeError('"value" argument is out of bounds');
|
|
1073
|
+
if (offset + ext > buf.length)
|
|
1074
|
+
throw new RangeError('Index out of range');
|
|
834
1075
|
}
|
|
835
1076
|
function wrtBigUInt64LE(buf, value, offset, min, max) {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
1077
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1078
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
1079
|
+
buf[offset++] = lo;
|
|
1080
|
+
lo = lo >> 8;
|
|
1081
|
+
buf[offset++] = lo;
|
|
1082
|
+
lo = lo >> 8;
|
|
1083
|
+
buf[offset++] = lo;
|
|
1084
|
+
lo = lo >> 8;
|
|
1085
|
+
buf[offset++] = lo;
|
|
1086
|
+
let hi = Number((value >> BigInt(32)) & BigInt(0xffffffff));
|
|
1087
|
+
buf[offset++] = hi;
|
|
1088
|
+
hi = hi >> 8;
|
|
1089
|
+
buf[offset++] = hi;
|
|
1090
|
+
hi = hi >> 8;
|
|
1091
|
+
buf[offset++] = hi;
|
|
1092
|
+
hi = hi >> 8;
|
|
1093
|
+
buf[offset++] = hi;
|
|
1094
|
+
return offset;
|
|
854
1095
|
}
|
|
855
1096
|
function wrtBigUInt64BE(buf, value, offset, min, max) {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1097
|
+
checkIntBI(value, min, max, buf, offset, 7);
|
|
1098
|
+
let lo = Number(value & BigInt(0xffffffff));
|
|
1099
|
+
buf[offset + 7] = lo;
|
|
1100
|
+
lo = lo >> 8;
|
|
1101
|
+
buf[offset + 6] = lo;
|
|
1102
|
+
lo = lo >> 8;
|
|
1103
|
+
buf[offset + 5] = lo;
|
|
1104
|
+
lo = lo >> 8;
|
|
1105
|
+
buf[offset + 4] = lo;
|
|
1106
|
+
let hi = Number((value >> BigInt(32)) & BigInt(0xffffffff));
|
|
1107
|
+
buf[offset + 3] = hi;
|
|
1108
|
+
hi = hi >> 8;
|
|
1109
|
+
buf[offset + 2] = hi;
|
|
1110
|
+
hi = hi >> 8;
|
|
1111
|
+
buf[offset + 1] = hi;
|
|
1112
|
+
hi = hi >> 8;
|
|
1113
|
+
buf[offset] = hi;
|
|
1114
|
+
return offset + 8;
|
|
874
1115
|
}
|
|
1116
|
+
// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
|
|
1117
|
+
// https://github.com/feross/buffer/pull/148
|
|
1118
|
+
// Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
|
|
1119
|
+
// Object.setPrototypeOf(Buffer, Uint8Array);
|
|
875
1120
|
function assertSize(size) {
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1121
|
+
if (typeof size !== 'number') {
|
|
1122
|
+
throw new TypeError('"size" argument must be of type number');
|
|
1123
|
+
}
|
|
1124
|
+
else if (size < 0) {
|
|
1125
|
+
throw new RangeError(`The value "${size}" is invalid for option "size"`);
|
|
1126
|
+
}
|
|
881
1127
|
}
|
|
882
1128
|
function alloc(size, fill, encoding) {
|
|
883
|
-
|
|
884
|
-
|
|
1129
|
+
assertSize(size);
|
|
1130
|
+
if (size <= 0) {
|
|
1131
|
+
return new Buffer(size);
|
|
1132
|
+
}
|
|
1133
|
+
if (fill !== undefined) {
|
|
1134
|
+
// Only pay attention to encoding if it's a string. This
|
|
1135
|
+
// prevents accidentally sending in a number that would
|
|
1136
|
+
// be interpreted as a start offset.
|
|
1137
|
+
return typeof encoding === 'string'
|
|
1138
|
+
? new Buffer(size).fill(fill, encoding)
|
|
1139
|
+
: new Buffer(size).fill(fill);
|
|
1140
|
+
}
|
|
885
1141
|
return new Buffer(size);
|
|
886
|
-
}
|
|
887
|
-
if (fill !== undefined) {
|
|
888
|
-
return typeof encoding === 'string' ? new Buffer(size).fill(fill, encoding) : new Buffer(size).fill(fill);
|
|
889
|
-
}
|
|
890
|
-
return new Buffer(size);
|
|
891
1142
|
}
|
|
892
1143
|
function fromString(string, encoding) {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1144
|
+
if (typeof encoding !== 'string' || encoding === '') {
|
|
1145
|
+
encoding = 'utf8';
|
|
1146
|
+
}
|
|
1147
|
+
if (!Buffer.isEncoding(encoding)) {
|
|
1148
|
+
throw new TypeError(`Unknown encoding: ${encoding}`);
|
|
1149
|
+
}
|
|
1150
|
+
const length = byteLength(string, encoding) | 0;
|
|
1151
|
+
let buf = new Buffer(length);
|
|
1152
|
+
const actual = buf.write(string, encoding);
|
|
1153
|
+
if (actual !== length) {
|
|
1154
|
+
// Writing a hex string, for example, that contains invalid characters will
|
|
1155
|
+
// cause everything after the first invalid character to be ignored. (e.g.
|
|
1156
|
+
// 'abxxcd' will be treated as 'ab')
|
|
1157
|
+
buf = buf.slice(0, actual);
|
|
1158
|
+
}
|
|
1159
|
+
return buf;
|
|
906
1160
|
}
|
|
907
1161
|
function fromArrayLike(array) {
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
1162
|
+
const length = array.length < 0 ? 0 : checked(array.length) | 0;
|
|
1163
|
+
const buf = new Buffer(length);
|
|
1164
|
+
for (let i = 0; i < length; i += 1) {
|
|
1165
|
+
buf[i] = array[i] & 255;
|
|
1166
|
+
}
|
|
1167
|
+
return buf;
|
|
914
1168
|
}
|
|
915
1169
|
function fromArrayView(arrayView) {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
1170
|
+
if (isInstance(arrayView, Uint8Array)) {
|
|
1171
|
+
const copy = new Uint8Array(arrayView);
|
|
1172
|
+
return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
|
|
1173
|
+
}
|
|
1174
|
+
return fromArrayLike(arrayView);
|
|
921
1175
|
}
|
|
922
1176
|
function fromArrayBuffer(array, byteOffset, length) {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1177
|
+
if (byteOffset < 0 || array.byteLength < byteOffset) {
|
|
1178
|
+
throw new RangeError('"offset" is outside of buffer bounds');
|
|
1179
|
+
}
|
|
1180
|
+
if (array.byteLength < byteOffset + (length || 0)) {
|
|
1181
|
+
throw new RangeError('"length" is outside of buffer bounds');
|
|
1182
|
+
}
|
|
1183
|
+
let buf;
|
|
1184
|
+
if (byteOffset === undefined && length === undefined) {
|
|
1185
|
+
buf = new Uint8Array(array);
|
|
1186
|
+
}
|
|
1187
|
+
else if (length === undefined) {
|
|
1188
|
+
buf = new Uint8Array(array, byteOffset);
|
|
1189
|
+
}
|
|
1190
|
+
else {
|
|
1191
|
+
buf = new Uint8Array(array, byteOffset, length);
|
|
1192
|
+
}
|
|
1193
|
+
// Return an augmented `Uint8Array` instance
|
|
1194
|
+
Object.setPrototypeOf(buf, Buffer.prototype);
|
|
1195
|
+
return buf;
|
|
939
1196
|
}
|
|
940
1197
|
function fromObject(obj) {
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1198
|
+
if (Buffer.isBuffer(obj)) {
|
|
1199
|
+
const len = checked(obj.length) | 0;
|
|
1200
|
+
const buf = new Buffer(len);
|
|
1201
|
+
if (buf.length === 0) {
|
|
1202
|
+
return buf;
|
|
1203
|
+
}
|
|
1204
|
+
obj.copy(buf, 0, 0, len);
|
|
1205
|
+
return buf;
|
|
1206
|
+
}
|
|
1207
|
+
if (obj.length !== undefined) {
|
|
1208
|
+
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
1209
|
+
return new Buffer(0);
|
|
1210
|
+
}
|
|
1211
|
+
return fromArrayLike(obj);
|
|
1212
|
+
}
|
|
1213
|
+
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
1214
|
+
return fromArrayLike(obj.data);
|
|
946
1215
|
}
|
|
947
|
-
obj.copy(buf, 0, 0, len);
|
|
948
|
-
return buf;
|
|
949
|
-
}
|
|
950
|
-
if (obj.length !== undefined) {
|
|
951
|
-
if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
|
|
952
|
-
return new Buffer(0);
|
|
953
|
-
}
|
|
954
|
-
return fromArrayLike(obj);
|
|
955
|
-
}
|
|
956
|
-
if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
|
|
957
|
-
return fromArrayLike(obj.data);
|
|
958
|
-
}
|
|
959
1216
|
}
|
|
960
1217
|
function checked(length) {
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1218
|
+
// Note: cannot use `length < kMaxLength` here because that fails when
|
|
1219
|
+
// length is NaN (which is otherwise coerced to zero.)
|
|
1220
|
+
if (length >= kMaxLength) {
|
|
1221
|
+
throw new RangeError(`${'Attempt to allocate Buffer larger than maximum ' + 'size: 0x'}${kMaxLength.toString(16)} bytes`);
|
|
1222
|
+
}
|
|
1223
|
+
return length | 0;
|
|
965
1224
|
}
|
|
966
1225
|
function byteLength(string, encoding) {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1226
|
+
if (Buffer.isBuffer(string)) {
|
|
1227
|
+
return string.length;
|
|
1228
|
+
}
|
|
1229
|
+
if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
|
|
1230
|
+
return string.byteLength;
|
|
1231
|
+
}
|
|
1232
|
+
if (typeof string !== 'string') {
|
|
1233
|
+
throw new TypeError(`${'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' +
|
|
1234
|
+
'Received type '}${typeof string}`);
|
|
1235
|
+
}
|
|
1236
|
+
const len = string.length;
|
|
1237
|
+
const mustMatch = arguments.length > 2 && arguments[2] === true;
|
|
1238
|
+
if (!mustMatch && len === 0)
|
|
1239
|
+
return 0;
|
|
1240
|
+
// Use a for loop to avoid recursion
|
|
1241
|
+
let loweredCase = false;
|
|
1242
|
+
for (;;) {
|
|
1243
|
+
switch (encoding) {
|
|
1244
|
+
case 'ascii':
|
|
1245
|
+
case 'latin1':
|
|
1246
|
+
case 'binary':
|
|
1247
|
+
return len;
|
|
1248
|
+
case 'utf8':
|
|
1249
|
+
case 'utf-8':
|
|
1250
|
+
return utf8ToBytes(string).length;
|
|
1251
|
+
case 'ucs2':
|
|
1252
|
+
case 'ucs-2':
|
|
1253
|
+
case 'utf16le':
|
|
1254
|
+
case 'utf-16le':
|
|
1255
|
+
return len * 2;
|
|
1256
|
+
case 'hex':
|
|
1257
|
+
return len >>> 1;
|
|
1258
|
+
case 'base64':
|
|
1259
|
+
return base64ToBytes(string).length;
|
|
1260
|
+
default:
|
|
1261
|
+
if (loweredCase) {
|
|
1262
|
+
return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
|
|
1263
|
+
}
|
|
1264
|
+
encoding = `${encoding}`.toLowerCase();
|
|
1265
|
+
loweredCase = true;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1006
1268
|
}
|
|
1269
|
+
// Buffer.byteLength = byteLength;
|
|
1007
1270
|
function swap(b, n, m) {
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1271
|
+
const i = b[n];
|
|
1272
|
+
b[n] = b[m];
|
|
1273
|
+
b[m] = i;
|
|
1011
1274
|
}
|
|
1275
|
+
// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
|
|
1276
|
+
// OR the last index of `val` in `buffer` at offset <= `byteOffset`.
|
|
1277
|
+
//
|
|
1278
|
+
// Arguments:
|
|
1279
|
+
// - buffer - a Buffer to search
|
|
1280
|
+
// - val - a string, Buffer, or number
|
|
1281
|
+
// - byteOffset - an index into `buffer`; will be clamped to an int32
|
|
1282
|
+
// - encoding - an optional encoding, relevant is val is a string
|
|
1283
|
+
// - dir - true for indexOf, false for lastIndexOf
|
|
1012
1284
|
function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
if (
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1285
|
+
// Empty buffer means no match
|
|
1286
|
+
if (buffer.length === 0)
|
|
1287
|
+
return -1;
|
|
1288
|
+
// Normalize byteOffset
|
|
1289
|
+
if (typeof byteOffset === 'string') {
|
|
1290
|
+
encoding = byteOffset;
|
|
1291
|
+
byteOffset = 0;
|
|
1292
|
+
}
|
|
1293
|
+
else if (byteOffset > 0x7fffffff) {
|
|
1294
|
+
byteOffset = 0x7fffffff;
|
|
1295
|
+
}
|
|
1296
|
+
else if (byteOffset < -0x80000000) {
|
|
1297
|
+
byteOffset = -0x80000000;
|
|
1298
|
+
}
|
|
1299
|
+
byteOffset = Number(byteOffset); // Coerce to Number.
|
|
1300
|
+
if (numberIsNaN(byteOffset)) {
|
|
1301
|
+
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
|
|
1302
|
+
byteOffset = dir ? 0 : buffer.length - 1;
|
|
1303
|
+
}
|
|
1304
|
+
// Normalize byteOffset: negative offsets start from the end of the buffer
|
|
1305
|
+
if (byteOffset < 0)
|
|
1306
|
+
byteOffset = buffer.length + byteOffset;
|
|
1307
|
+
if (byteOffset >= buffer.length) {
|
|
1308
|
+
if (dir)
|
|
1309
|
+
return -1;
|
|
1310
|
+
byteOffset = buffer.length - 1;
|
|
1311
|
+
}
|
|
1312
|
+
else if (byteOffset < 0) {
|
|
1313
|
+
if (dir)
|
|
1314
|
+
byteOffset = 0;
|
|
1315
|
+
else
|
|
1316
|
+
return -1;
|
|
1317
|
+
}
|
|
1318
|
+
// Normalize val
|
|
1319
|
+
if (typeof val === 'string') {
|
|
1320
|
+
val = Buffer.from(val, encoding);
|
|
1321
|
+
}
|
|
1322
|
+
// Finally, search either indexOf (if dir is true) or lastIndexOf
|
|
1323
|
+
if (Buffer.isBuffer(val)) {
|
|
1324
|
+
// Special case: looking for empty string/buffer always fails
|
|
1325
|
+
if (val.length === 0) {
|
|
1326
|
+
return -1;
|
|
1327
|
+
}
|
|
1328
|
+
return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
|
|
1329
|
+
}
|
|
1330
|
+
else if (typeof val === 'number') {
|
|
1331
|
+
val = val & 0xff; // Search for a byte value [0-255]
|
|
1332
|
+
if (typeof Uint8Array.prototype.indexOf === 'function') {
|
|
1333
|
+
if (dir) {
|
|
1334
|
+
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
|
|
1335
|
+
}
|
|
1336
|
+
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
|
|
1337
|
+
}
|
|
1338
|
+
return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
|
|
1339
|
+
}
|
|
1340
|
+
throw new TypeError('val must be string, number or Buffer');
|
|
1052
1341
|
}
|
|
1053
1342
|
function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1343
|
+
let indexSize = 1;
|
|
1344
|
+
let arrLength = arr.length;
|
|
1345
|
+
let valLength = val.length;
|
|
1346
|
+
if (encoding !== undefined) {
|
|
1347
|
+
encoding = String(encoding).toLowerCase();
|
|
1348
|
+
if (encoding === 'ucs2' ||
|
|
1349
|
+
encoding === 'ucs-2' ||
|
|
1350
|
+
encoding === 'utf16le' ||
|
|
1351
|
+
encoding === 'utf-16le') {
|
|
1352
|
+
if (arr.length < 2 || val.length < 2) {
|
|
1353
|
+
return -1;
|
|
1354
|
+
}
|
|
1355
|
+
indexSize = 2;
|
|
1356
|
+
arrLength /= 2;
|
|
1357
|
+
valLength /= 2;
|
|
1358
|
+
byteOffset /= 2;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
function read(buf, i) {
|
|
1362
|
+
if (indexSize === 1) {
|
|
1363
|
+
return buf[i];
|
|
1364
|
+
}
|
|
1365
|
+
return buf.readUInt16BE(i * indexSize);
|
|
1366
|
+
}
|
|
1367
|
+
let i;
|
|
1368
|
+
if (dir) {
|
|
1369
|
+
let foundIndex = -1;
|
|
1370
|
+
for (i = byteOffset; i < arrLength; i++) {
|
|
1371
|
+
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
|
|
1372
|
+
if (foundIndex === -1)
|
|
1373
|
+
foundIndex = i;
|
|
1374
|
+
if (i - foundIndex + 1 === valLength)
|
|
1375
|
+
return foundIndex * indexSize;
|
|
1376
|
+
}
|
|
1377
|
+
else {
|
|
1378
|
+
if (foundIndex !== -1)
|
|
1379
|
+
i -= i - foundIndex;
|
|
1380
|
+
foundIndex = -1;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
else {
|
|
1385
|
+
if (byteOffset + valLength > arrLength)
|
|
1386
|
+
byteOffset = arrLength - valLength;
|
|
1387
|
+
for (i = byteOffset; i >= 0; i--) {
|
|
1388
|
+
let found = true;
|
|
1389
|
+
for (let j = 0; j < valLength; j++) {
|
|
1390
|
+
if (read(arr, i + j) !== read(val, j)) {
|
|
1391
|
+
found = false;
|
|
1392
|
+
break;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
if (found)
|
|
1396
|
+
return i;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
return -1;
|
|
1101
1400
|
}
|
|
1102
1401
|
function hexWrite(buf, string, offset, length) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
length
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1402
|
+
offset = Number(offset) || 0;
|
|
1403
|
+
const remaining = buf.length - offset;
|
|
1404
|
+
if (!length) {
|
|
1405
|
+
length = remaining;
|
|
1406
|
+
}
|
|
1407
|
+
else {
|
|
1408
|
+
length = Number(length);
|
|
1409
|
+
if (length > remaining) {
|
|
1410
|
+
length = remaining;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
const strLen = string.length;
|
|
1414
|
+
if (length > strLen / 2) {
|
|
1415
|
+
length = strLen / 2;
|
|
1416
|
+
}
|
|
1417
|
+
let i;
|
|
1418
|
+
for (i = 0; i < length; ++i) {
|
|
1419
|
+
const parsed = parseInt(string.substr(i * 2, 2), 16);
|
|
1420
|
+
if (numberIsNaN(parsed))
|
|
1421
|
+
return i;
|
|
1422
|
+
buf[offset + i] = parsed;
|
|
1423
|
+
}
|
|
1424
|
+
return i;
|
|
1124
1425
|
}
|
|
1125
1426
|
function utf8Write(buf, string, offset, length) {
|
|
1126
|
-
|
|
1427
|
+
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
|
|
1127
1428
|
}
|
|
1128
1429
|
function asciiWrite(buf, string, offset, length) {
|
|
1129
|
-
|
|
1430
|
+
return blitBuffer(asciiToBytes(string), buf, offset, length);
|
|
1130
1431
|
}
|
|
1131
1432
|
function base64Write(buf, string, offset, length) {
|
|
1132
|
-
|
|
1433
|
+
return blitBuffer(base64ToBytes(string), buf, offset, length);
|
|
1133
1434
|
}
|
|
1134
1435
|
function ucs2Write(buf, string, offset, length) {
|
|
1135
|
-
|
|
1436
|
+
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
|
|
1136
1437
|
}
|
|
1137
1438
|
function base64Slice(buf, start, end) {
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1439
|
+
if (start === 0 && end === buf.length) {
|
|
1440
|
+
return base64.fromByteArray(buf);
|
|
1441
|
+
}
|
|
1442
|
+
return base64.fromByteArray(buf.slice(start, end));
|
|
1142
1443
|
}
|
|
1143
1444
|
function utf8Slice(buf, start, end) {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1445
|
+
end = Math.min(buf.length, end);
|
|
1446
|
+
const res = [];
|
|
1447
|
+
let i = start;
|
|
1448
|
+
while (i < end) {
|
|
1449
|
+
const firstByte = buf[i];
|
|
1450
|
+
let codePoint = null;
|
|
1451
|
+
let bytesPerSequence = firstByte > 0xef ? 4 : firstByte > 0xdf ? 3 : firstByte > 0xbf ? 2 : 1;
|
|
1452
|
+
if (i + bytesPerSequence <= end) {
|
|
1453
|
+
let fourthByte;
|
|
1454
|
+
let secondByte;
|
|
1455
|
+
let tempCodePoint;
|
|
1456
|
+
let thirdByte;
|
|
1457
|
+
switch (bytesPerSequence) {
|
|
1458
|
+
case 1:
|
|
1459
|
+
if (firstByte < 0x80) {
|
|
1460
|
+
codePoint = firstByte;
|
|
1461
|
+
}
|
|
1462
|
+
break;
|
|
1463
|
+
case 2:
|
|
1464
|
+
secondByte = buf[i + 1];
|
|
1465
|
+
if ((secondByte & 0xc0) === 0x80) {
|
|
1466
|
+
tempCodePoint = ((firstByte & 0x1f) << 0x6) | (secondByte & 0x3f);
|
|
1467
|
+
if (tempCodePoint > 0x7f) {
|
|
1468
|
+
codePoint = tempCodePoint;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
break;
|
|
1472
|
+
case 3:
|
|
1473
|
+
secondByte = buf[i + 1];
|
|
1474
|
+
thirdByte = buf[i + 2];
|
|
1475
|
+
if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80) {
|
|
1476
|
+
tempCodePoint =
|
|
1477
|
+
((firstByte & 0xf) << 0xc) | ((secondByte & 0x3f) << 0x6) | (thirdByte & 0x3f);
|
|
1478
|
+
if (tempCodePoint > 0x7ff && (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff)) {
|
|
1479
|
+
codePoint = tempCodePoint;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
break;
|
|
1483
|
+
case 4:
|
|
1484
|
+
secondByte = buf[i + 1];
|
|
1485
|
+
thirdByte = buf[i + 2];
|
|
1486
|
+
fourthByte = buf[i + 3];
|
|
1487
|
+
if ((secondByte & 0xc0) === 0x80 &&
|
|
1488
|
+
(thirdByte & 0xc0) === 0x80 &&
|
|
1489
|
+
(fourthByte & 0xc0) === 0x80) {
|
|
1490
|
+
tempCodePoint =
|
|
1491
|
+
((firstByte & 0xf) << 0x12) |
|
|
1492
|
+
((secondByte & 0x3f) << 0xc) |
|
|
1493
|
+
((thirdByte & 0x3f) << 0x6) |
|
|
1494
|
+
(fourthByte & 0x3f);
|
|
1495
|
+
if (tempCodePoint > 0xffff && tempCodePoint < 0x110000) {
|
|
1496
|
+
codePoint = tempCodePoint;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1189
1499
|
}
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1500
|
+
}
|
|
1501
|
+
if (codePoint === null) {
|
|
1502
|
+
// we did not generate a valid codePoint so insert a
|
|
1503
|
+
// replacement char (U+FFFD) and advance only 1 byte
|
|
1504
|
+
codePoint = 0xfffd;
|
|
1505
|
+
bytesPerSequence = 1;
|
|
1506
|
+
}
|
|
1507
|
+
else if (codePoint > 0xffff) {
|
|
1508
|
+
// encode to utf16 (surrogate pair dance)
|
|
1509
|
+
codePoint -= 0x10000;
|
|
1510
|
+
res.push(((codePoint >>> 10) & 0x3ff) | 0xd800);
|
|
1511
|
+
codePoint = 0xdc00 | (codePoint & 0x3ff);
|
|
1512
|
+
}
|
|
1513
|
+
res.push(codePoint);
|
|
1514
|
+
i += bytesPerSequence;
|
|
1515
|
+
}
|
|
1516
|
+
return decodeCodePointsArray(res);
|
|
1205
1517
|
}
|
|
1518
|
+
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
|
|
1519
|
+
// the lowest limit is Chrome, with 0x10000 args.
|
|
1520
|
+
// We go 1 magnitude less, for safety
|
|
1206
1521
|
const MAX_ARGUMENTS_LENGTH = 0x1000;
|
|
1207
1522
|
function decodeCodePointsArray(codePoints) {
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1523
|
+
const len = codePoints.length;
|
|
1524
|
+
if (len <= MAX_ARGUMENTS_LENGTH) {
|
|
1525
|
+
return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
|
|
1526
|
+
}
|
|
1527
|
+
// Decode in chunks to avoid "call stack size exceeded".
|
|
1528
|
+
let res = '';
|
|
1529
|
+
let i = 0;
|
|
1530
|
+
while (i < len) {
|
|
1531
|
+
res += String.fromCharCode.apply(String, codePoints.slice(i, (i += MAX_ARGUMENTS_LENGTH)));
|
|
1532
|
+
}
|
|
1533
|
+
return res;
|
|
1218
1534
|
}
|
|
1219
1535
|
function asciiSlice(buf, start, end) {
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1536
|
+
let ret = '';
|
|
1537
|
+
end = Math.min(buf.length, end);
|
|
1538
|
+
for (let i = start; i < end; ++i) {
|
|
1539
|
+
ret += String.fromCharCode(buf[i] & 0x7f);
|
|
1540
|
+
}
|
|
1541
|
+
return ret;
|
|
1226
1542
|
}
|
|
1227
1543
|
function latin1Slice(buf, start, end) {
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1544
|
+
let ret = '';
|
|
1545
|
+
end = Math.min(buf.length, end);
|
|
1546
|
+
for (let i = start; i < end; ++i) {
|
|
1547
|
+
ret += String.fromCharCode(buf[i]);
|
|
1548
|
+
}
|
|
1549
|
+
return ret;
|
|
1234
1550
|
}
|
|
1235
1551
|
function hexSlice(buf, start, end) {
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
out
|
|
1242
|
-
|
|
1243
|
-
|
|
1552
|
+
const len = buf.length;
|
|
1553
|
+
if (!start || start < 0)
|
|
1554
|
+
start = 0;
|
|
1555
|
+
if (!end || end < 0 || end > len)
|
|
1556
|
+
end = len;
|
|
1557
|
+
let out = '';
|
|
1558
|
+
for (let i = start; i < end; ++i) {
|
|
1559
|
+
out += hexSliceLookupTable[buf[i]];
|
|
1560
|
+
}
|
|
1561
|
+
return out;
|
|
1244
1562
|
}
|
|
1245
1563
|
function utf16leSlice(buf, start, end) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1564
|
+
const bytes = buf.slice(start, end);
|
|
1565
|
+
let res = '';
|
|
1566
|
+
// If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
|
|
1567
|
+
for (let i = 0; i < bytes.length - 1; i += 2) {
|
|
1568
|
+
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
|
|
1569
|
+
}
|
|
1570
|
+
return res;
|
|
1252
1571
|
}
|
|
1572
|
+
/*
|
|
1573
|
+
* Need to make sure that buffer isn't trying to write out of bounds.
|
|
1574
|
+
*/
|
|
1253
1575
|
function checkOffset(offset, ext, length) {
|
|
1254
|
-
|
|
1255
|
-
|
|
1576
|
+
if (offset % 1 !== 0 || offset < 0)
|
|
1577
|
+
throw new RangeError('offset is not uint');
|
|
1578
|
+
if (offset + ext > length)
|
|
1579
|
+
throw new RangeError('Trying to access beyond buffer length');
|
|
1256
1580
|
}
|
|
1257
1581
|
function checkIEEE754(buf, value, offset, ext, max, min) {
|
|
1258
|
-
|
|
1259
|
-
|
|
1582
|
+
if (offset + ext > buf.length)
|
|
1583
|
+
throw new RangeError('Index out of range');
|
|
1584
|
+
if (offset < 0)
|
|
1585
|
+
throw new RangeError('Index out of range');
|
|
1260
1586
|
}
|
|
1261
1587
|
function writeFloat(buf, value, offset, littleEndian, noAssert) {
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1588
|
+
value = Number(value);
|
|
1589
|
+
offset = offset >>> 0;
|
|
1590
|
+
if (!noAssert) {
|
|
1591
|
+
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e38, -3.4028234663852886e38);
|
|
1592
|
+
}
|
|
1593
|
+
ieee754.write(buf, value, offset, littleEndian, 23, 4);
|
|
1594
|
+
return offset + 4;
|
|
1269
1595
|
}
|
|
1270
1596
|
function writeDouble(buf, value, offset, littleEndian, noAssert) {
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1597
|
+
value = Number(value);
|
|
1598
|
+
offset = offset >>> 0;
|
|
1599
|
+
if (!noAssert) {
|
|
1600
|
+
checkIEEE754(buf, value, offset, 8, 1.7976931348623157e308, -1.7976931348623157e308);
|
|
1601
|
+
}
|
|
1602
|
+
ieee754.write(buf, value, offset, littleEndian, 52, 8);
|
|
1603
|
+
return offset + 8;
|
|
1278
1604
|
}
|
|
1605
|
+
// CUSTOM ERRORS
|
|
1606
|
+
// =============
|
|
1607
|
+
// Simplified versions from Node, changed for Buffer-only usage
|
|
1279
1608
|
const errors = {};
|
|
1280
1609
|
function E(sym, getMessage, Base) {
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
value
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1610
|
+
errors[sym] = class NodeError extends Base {
|
|
1611
|
+
constructor() {
|
|
1612
|
+
super();
|
|
1613
|
+
Object.defineProperty(this, 'message', {
|
|
1614
|
+
value: getMessage.apply(this, arguments),
|
|
1615
|
+
writable: true,
|
|
1616
|
+
configurable: true
|
|
1617
|
+
});
|
|
1618
|
+
// Add the error code to the name to include it in the stack trace.
|
|
1619
|
+
this.name = `${this.name} [${sym}]`;
|
|
1620
|
+
// Access the stack to generate the error message including the error code
|
|
1621
|
+
// from the name.
|
|
1622
|
+
this.stack; // eslint-disable-line no-unused-expressions
|
|
1623
|
+
// Reset the name to the actual name.
|
|
1624
|
+
delete this.name;
|
|
1625
|
+
}
|
|
1626
|
+
get code() {
|
|
1627
|
+
return sym;
|
|
1628
|
+
}
|
|
1629
|
+
set code(value) {
|
|
1630
|
+
Object.defineProperty(this, 'code', {
|
|
1631
|
+
configurable: true,
|
|
1632
|
+
enumerable: true,
|
|
1633
|
+
value,
|
|
1634
|
+
writable: true
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
toString() {
|
|
1638
|
+
return `${this.name} [${sym}]: ${this.message}`;
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1308
1641
|
}
|
|
1309
1642
|
E('ERR_BUFFER_OUT_OF_BOUNDS', function (name) {
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1643
|
+
if (name) {
|
|
1644
|
+
return `${name} is outside of buffer bounds`;
|
|
1645
|
+
}
|
|
1646
|
+
return 'Attempt to access memory outside buffer bounds';
|
|
1314
1647
|
}, RangeError);
|
|
1315
1648
|
E('ERR_INVALID_ARG_TYPE', function (name, actual) {
|
|
1316
|
-
|
|
1649
|
+
return `The "${name}" argument must be of type number. Received type ${typeof actual}`;
|
|
1317
1650
|
}, TypeError);
|
|
1318
1651
|
E('ERR_OUT_OF_RANGE', function (str, range, input) {
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1652
|
+
let msg = `The value of "${str}" is out of range.`;
|
|
1653
|
+
let received = input;
|
|
1654
|
+
if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) {
|
|
1655
|
+
received = addNumericalSeparator(String(input));
|
|
1656
|
+
}
|
|
1657
|
+
else if (typeof input === 'bigint') {
|
|
1658
|
+
received = String(input);
|
|
1659
|
+
if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) {
|
|
1660
|
+
received = addNumericalSeparator(received);
|
|
1661
|
+
}
|
|
1662
|
+
received += 'n';
|
|
1663
|
+
}
|
|
1664
|
+
msg += ` It must be ${range}. Received ${received}`;
|
|
1665
|
+
return msg;
|
|
1332
1666
|
}, RangeError);
|
|
1333
1667
|
function addNumericalSeparator(val) {
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1668
|
+
let res = '';
|
|
1669
|
+
let i = val.length;
|
|
1670
|
+
const start = val[0] === '-' ? 1 : 0;
|
|
1671
|
+
for (; i >= start + 4; i -= 3) {
|
|
1672
|
+
res = `_${val.slice(i - 3, i)}${res}`;
|
|
1673
|
+
}
|
|
1674
|
+
return `${val.slice(0, i)}${res}`;
|
|
1341
1675
|
}
|
|
1676
|
+
// CHECK FUNCTIONS
|
|
1677
|
+
// ===============
|
|
1342
1678
|
function checkBounds(buf, offset, byteLength) {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1679
|
+
validateNumber(offset, 'offset');
|
|
1680
|
+
if (buf[offset] === undefined || buf[offset + byteLength] === undefined) {
|
|
1681
|
+
boundsError(offset, buf.length - (byteLength + 1));
|
|
1682
|
+
}
|
|
1347
1683
|
}
|
|
1348
1684
|
function checkIntBI(value, min, max, buf, offset, byteLength) {
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1685
|
+
if (value > max || value < min) {
|
|
1686
|
+
const n = typeof min === 'bigint' ? 'n' : '';
|
|
1687
|
+
let range;
|
|
1688
|
+
if (byteLength > 3) {
|
|
1689
|
+
if (min === 0 || min === BigInt(0)) {
|
|
1690
|
+
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
1691
|
+
}
|
|
1692
|
+
else {
|
|
1693
|
+
range =
|
|
1694
|
+
`>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
1695
|
+
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
else {
|
|
1699
|
+
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
1700
|
+
}
|
|
1701
|
+
throw new errors.ERR_OUT_OF_RANGE('value', range, value);
|
|
1702
|
+
}
|
|
1703
|
+
checkBounds(buf, offset, byteLength);
|
|
1364
1704
|
}
|
|
1365
1705
|
function validateNumber(value, name) {
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1706
|
+
if (typeof value !== 'number') {
|
|
1707
|
+
throw new errors.ERR_INVALID_ARG_TYPE(name, 'number', value);
|
|
1708
|
+
}
|
|
1369
1709
|
}
|
|
1370
1710
|
function boundsError(value, length, type) {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1711
|
+
if (Math.floor(value) !== value) {
|
|
1712
|
+
validateNumber(value, type);
|
|
1713
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value);
|
|
1714
|
+
}
|
|
1715
|
+
if (length < 0) {
|
|
1716
|
+
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS();
|
|
1717
|
+
}
|
|
1718
|
+
throw new errors.ERR_OUT_OF_RANGE(type || 'offset', `>= ${type ? 1 : 0} and <= ${length}`, value);
|
|
1379
1719
|
}
|
|
1720
|
+
// HELPER FUNCTIONS
|
|
1721
|
+
// ================
|
|
1380
1722
|
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
|
|
1381
1723
|
function base64clean(str) {
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1724
|
+
// Node takes equal signs as end of the Base64 encoding
|
|
1725
|
+
str = str.split('=')[0];
|
|
1726
|
+
// Node strips out invalid characters like \n and \t from the string, base64-js does not
|
|
1727
|
+
str = str.trim().replace(INVALID_BASE64_RE, '');
|
|
1728
|
+
// Node converts strings with length < 2 to ''
|
|
1729
|
+
if (str.length < 2)
|
|
1730
|
+
return '';
|
|
1731
|
+
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
|
|
1732
|
+
while (str.length % 4 !== 0) {
|
|
1733
|
+
str = `${str}=`;
|
|
1734
|
+
}
|
|
1735
|
+
return str;
|
|
1389
1736
|
}
|
|
1390
1737
|
function utf8ToBytes(string, units) {
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1738
|
+
units = units || Infinity;
|
|
1739
|
+
let codePoint;
|
|
1740
|
+
const length = string.length;
|
|
1741
|
+
let leadSurrogate = null;
|
|
1742
|
+
const bytes = [];
|
|
1743
|
+
for (let i = 0; i < length; ++i) {
|
|
1744
|
+
codePoint = string.charCodeAt(i);
|
|
1745
|
+
// is surrogate component
|
|
1746
|
+
if (codePoint > 0xd7ff && codePoint < 0xe000) {
|
|
1747
|
+
// last char was a lead
|
|
1748
|
+
if (!leadSurrogate) {
|
|
1749
|
+
// no lead yet
|
|
1750
|
+
if (codePoint > 0xdbff) {
|
|
1751
|
+
// unexpected trail
|
|
1752
|
+
if ((units -= 3) > -1)
|
|
1753
|
+
bytes.push(0xef, 0xbf, 0xbd);
|
|
1754
|
+
continue;
|
|
1755
|
+
}
|
|
1756
|
+
else if (i + 1 === length) {
|
|
1757
|
+
// unpaired lead
|
|
1758
|
+
if ((units -= 3) > -1)
|
|
1759
|
+
bytes.push(0xef, 0xbf, 0xbd);
|
|
1760
|
+
continue;
|
|
1761
|
+
}
|
|
1762
|
+
// valid lead
|
|
1763
|
+
leadSurrogate = codePoint;
|
|
1764
|
+
continue;
|
|
1765
|
+
}
|
|
1766
|
+
// 2 leads in a row
|
|
1767
|
+
if (codePoint < 0xdc00) {
|
|
1768
|
+
if ((units -= 3) > -1)
|
|
1769
|
+
bytes.push(0xef, 0xbf, 0xbd);
|
|
1770
|
+
leadSurrogate = codePoint;
|
|
1771
|
+
continue;
|
|
1772
|
+
}
|
|
1773
|
+
// valid surrogate pair
|
|
1774
|
+
codePoint = (((leadSurrogate - 0xd800) << 10) | (codePoint - 0xdc00)) + 0x10000;
|
|
1775
|
+
}
|
|
1776
|
+
else if (leadSurrogate) {
|
|
1777
|
+
// valid bmp char, but last char was a lead
|
|
1778
|
+
if ((units -= 3) > -1)
|
|
1779
|
+
bytes.push(0xef, 0xbf, 0xbd);
|
|
1780
|
+
}
|
|
1781
|
+
leadSurrogate = null;
|
|
1782
|
+
// encode utf8
|
|
1783
|
+
if (codePoint < 0x80) {
|
|
1784
|
+
if ((units -= 1) < 0)
|
|
1785
|
+
break;
|
|
1786
|
+
bytes.push(codePoint);
|
|
1787
|
+
}
|
|
1788
|
+
else if (codePoint < 0x800) {
|
|
1789
|
+
if ((units -= 2) < 0)
|
|
1790
|
+
break;
|
|
1791
|
+
bytes.push((codePoint >> 0x6) | 0xc0, (codePoint & 0x3f) | 0x80);
|
|
1792
|
+
}
|
|
1793
|
+
else if (codePoint < 0x10000) {
|
|
1794
|
+
if ((units -= 3) < 0)
|
|
1795
|
+
break;
|
|
1796
|
+
bytes.push((codePoint >> 0xc) | 0xe0, ((codePoint >> 0x6) & 0x3f) | 0x80, (codePoint & 0x3f) | 0x80);
|
|
1797
|
+
}
|
|
1798
|
+
else if (codePoint < 0x110000) {
|
|
1799
|
+
if ((units -= 4) < 0)
|
|
1800
|
+
break;
|
|
1801
|
+
bytes.push((codePoint >> 0x12) | 0xf0, ((codePoint >> 0xc) & 0x3f) | 0x80, ((codePoint >> 0x6) & 0x3f) | 0x80, (codePoint & 0x3f) | 0x80);
|
|
1802
|
+
}
|
|
1803
|
+
else {
|
|
1804
|
+
throw new Error('Invalid code point');
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
return bytes;
|
|
1437
1808
|
}
|
|
1438
1809
|
function asciiToBytes(str) {
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1810
|
+
const byteArray = [];
|
|
1811
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1812
|
+
// Node's code seems to be doing this and not & 0x7F..
|
|
1813
|
+
byteArray.push(str.charCodeAt(i) & 0xff);
|
|
1814
|
+
}
|
|
1815
|
+
return byteArray;
|
|
1444
1816
|
}
|
|
1445
1817
|
function utf16leToBytes(str, units) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1818
|
+
let c;
|
|
1819
|
+
let hi;
|
|
1820
|
+
let lo;
|
|
1821
|
+
const byteArray = [];
|
|
1822
|
+
for (let i = 0; i < str.length; ++i) {
|
|
1823
|
+
if ((units -= 2) < 0)
|
|
1824
|
+
break;
|
|
1825
|
+
c = str.charCodeAt(i);
|
|
1826
|
+
hi = c >> 8;
|
|
1827
|
+
lo = c % 256;
|
|
1828
|
+
byteArray.push(lo);
|
|
1829
|
+
byteArray.push(hi);
|
|
1830
|
+
}
|
|
1831
|
+
return byteArray;
|
|
1459
1832
|
}
|
|
1460
1833
|
function base64ToBytes(str) {
|
|
1461
|
-
|
|
1834
|
+
return base64.toByteArray(base64clean(str));
|
|
1462
1835
|
}
|
|
1463
1836
|
function blitBuffer(src, dst, offset, length) {
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1837
|
+
let i;
|
|
1838
|
+
for (i = 0; i < length; ++i) {
|
|
1839
|
+
if (i + offset >= dst.length || i >= src.length)
|
|
1840
|
+
break;
|
|
1841
|
+
dst[i + offset] = src[i];
|
|
1842
|
+
}
|
|
1843
|
+
return i;
|
|
1470
1844
|
}
|
|
1845
|
+
// ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
|
|
1846
|
+
// the `instanceof` check but they should be treated as of that type.
|
|
1847
|
+
// See: https://github.com/feross/buffer/issues/166
|
|
1471
1848
|
function isInstance(obj, type) {
|
|
1472
|
-
|
|
1849
|
+
return (obj instanceof type ||
|
|
1850
|
+
(obj != null &&
|
|
1851
|
+
obj.constructor != null &&
|
|
1852
|
+
obj.constructor.name != null &&
|
|
1853
|
+
obj.constructor.name === type.name));
|
|
1473
1854
|
}
|
|
1474
1855
|
function numberIsNaN(obj) {
|
|
1475
|
-
|
|
1856
|
+
// For IE11 support
|
|
1857
|
+
return obj !== obj; // eslint-disable-line no-self-compare
|
|
1476
1858
|
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
const
|
|
1482
|
-
for (let
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1859
|
+
// Create lookup table for `toString('hex')`
|
|
1860
|
+
// See: https://github.com/feross/buffer/issues/219
|
|
1861
|
+
const hexSliceLookupTable = (function () {
|
|
1862
|
+
const alphabet = '0123456789abcdef';
|
|
1863
|
+
const table = new Array(256);
|
|
1864
|
+
for (let i = 0; i < 16; ++i) {
|
|
1865
|
+
const i16 = i * 16;
|
|
1866
|
+
for (let j = 0; j < 16; ++j) {
|
|
1867
|
+
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
return table;
|
|
1871
|
+
})();
|