@fluid-internal/client-utils 2.118.0 → 3.0.0
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/CHANGELOG.md +1 -5
- package/README.md +13 -15
- package/dist/base64EncodingBrowser.d.ts +2 -1
- package/dist/base64EncodingBrowser.d.ts.map +1 -1
- package/dist/base64EncodingBrowser.js +1 -1
- package/dist/base64EncodingBrowser.js.map +1 -1
- package/dist/base64EncodingNode.d.ts +2 -1
- package/dist/base64EncodingNode.d.ts.map +1 -1
- package/dist/base64EncodingNode.js.map +1 -1
- package/dist/buffer.d.ts +93 -0
- package/dist/buffer.d.ts.map +1 -0
- package/dist/buffer.js +7 -0
- package/dist/buffer.js.map +1 -0
- package/dist/bufferBrowser.d.ts +18 -49
- package/dist/bufferBrowser.d.ts.map +1 -1
- package/dist/bufferBrowser.js +49 -52
- package/dist/bufferBrowser.js.map +1 -1
- package/dist/bufferNode.d.ts +67 -19
- package/dist/bufferNode.d.ts.map +1 -1
- package/dist/bufferNode.js +10 -12
- package/dist/bufferNode.js.map +1 -1
- package/dist/bufferShared.d.ts +38 -3
- package/dist/bufferShared.d.ts.map +1 -1
- package/dist/bufferShared.js +67 -5
- package/dist/bufferShared.js.map +1 -1
- package/dist/events/emitter.d.ts.map +1 -1
- package/dist/events/emitter.js +4 -3
- package/dist/events/emitter.js.map +1 -1
- package/dist/hashFileBrowser.d.ts +1 -1
- package/dist/hashFileBrowser.d.ts.map +1 -1
- package/dist/hashFileBrowser.js +23 -11
- package/dist/hashFileBrowser.js.map +1 -1
- package/dist/hashFileNode.d.ts +10 -2
- package/dist/hashFileNode.d.ts.map +1 -1
- package/dist/hashFileNode.js +10 -3
- package/dist/hashFileNode.js.map +1 -1
- package/dist/indexBrowser.d.ts +5 -3
- package/dist/indexBrowser.d.ts.map +1 -1
- package/dist/indexBrowser.js +5 -5
- package/dist/indexBrowser.js.map +1 -1
- package/dist/indexNode.d.ts +4 -3
- package/dist/indexNode.d.ts.map +1 -1
- package/dist/indexNode.js +5 -2
- package/dist/indexNode.js.map +1 -1
- package/dist/layerCompat.d.ts +37 -13
- package/dist/layerCompat.d.ts.map +1 -1
- package/dist/layerCompat.js +19 -14
- package/dist/layerCompat.js.map +1 -1
- package/dist/trace.js +2 -0
- package/dist/trace.js.map +1 -1
- package/dist/typedEventEmitter.js +7 -0
- package/dist/typedEventEmitter.js.map +1 -1
- package/eslint.config.mts +2 -2
- package/lib/base64EncodingBrowser.d.ts +2 -1
- package/lib/base64EncodingBrowser.d.ts.map +1 -1
- package/lib/base64EncodingBrowser.js +1 -1
- package/lib/base64EncodingBrowser.js.map +1 -1
- package/lib/base64EncodingNode.d.ts +2 -1
- package/lib/base64EncodingNode.d.ts.map +1 -1
- package/lib/base64EncodingNode.js.map +1 -1
- package/lib/buffer.d.ts +93 -0
- package/lib/buffer.d.ts.map +1 -0
- package/lib/buffer.js +6 -0
- package/lib/buffer.js.map +1 -0
- package/lib/bufferBrowser.d.ts +18 -49
- package/lib/bufferBrowser.d.ts.map +1 -1
- package/lib/bufferBrowser.js +29 -40
- package/lib/bufferBrowser.js.map +1 -1
- package/lib/bufferNode.d.ts +67 -19
- package/lib/bufferNode.d.ts.map +1 -1
- package/lib/bufferNode.js +7 -9
- package/lib/bufferNode.js.map +1 -1
- package/lib/bufferShared.d.ts +38 -3
- package/lib/bufferShared.d.ts.map +1 -1
- package/lib/bufferShared.js +64 -3
- package/lib/bufferShared.js.map +1 -1
- package/lib/events/emitter.d.ts.map +1 -1
- package/lib/events/emitter.js +2 -1
- package/lib/events/emitter.js.map +1 -1
- package/lib/hashFileBrowser.d.ts +1 -1
- package/lib/hashFileBrowser.d.ts.map +1 -1
- package/lib/hashFileBrowser.js +4 -1
- package/lib/hashFileBrowser.js.map +1 -1
- package/lib/hashFileNode.d.ts +10 -2
- package/lib/hashFileNode.d.ts.map +1 -1
- package/lib/hashFileNode.js +8 -0
- package/lib/hashFileNode.js.map +1 -1
- package/lib/indexBrowser.d.ts +5 -3
- package/lib/indexBrowser.d.ts.map +1 -1
- package/lib/indexBrowser.js +3 -5
- package/lib/indexBrowser.js.map +1 -1
- package/lib/indexNode.d.ts +4 -3
- package/lib/indexNode.d.ts.map +1 -1
- package/lib/indexNode.js +2 -2
- package/lib/indexNode.js.map +1 -1
- package/lib/layerCompat.d.ts +37 -13
- package/lib/layerCompat.d.ts.map +1 -1
- package/lib/layerCompat.js +17 -12
- package/lib/layerCompat.js.map +1 -1
- package/lib/trace.js +2 -0
- package/lib/trace.js.map +1 -1
- package/lib/typedEventEmitter.js +7 -0
- package/lib/typedEventEmitter.js.map +1 -1
- package/package.json +65 -62
- package/playwright.config.ts +23 -0
- package/src/base64EncodingBrowser.ts +3 -2
- package/src/base64EncodingNode.ts +2 -1
- package/src/buffer.ts +112 -0
- package/src/bufferBrowser.ts +98 -60
- package/src/bufferNode.ts +86 -30
- package/src/bufferShared.ts +74 -4
- package/src/hashFileBrowser.ts +6 -3
- package/src/hashFileNode.ts +10 -2
- package/src/indexBrowser.ts +13 -2
- package/src/indexNode.ts +13 -2
- package/src/layerCompat.ts +41 -13
- package/tsconfig.json +1 -2
- package/webpack.playwright.cjs +22 -0
- package/jest-puppeteer.config.cjs +0 -16
- package/jest.config.cjs +0 -21
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -8,8 +8,9 @@ primarily within the client release group.
|
|
|
8
8
|
<!-- prettier-ignore-start -->
|
|
9
9
|
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
10
10
|
|
|
11
|
-
**IMPORTANT:
|
|
12
|
-
**
|
|
11
|
+
**IMPORTANT: Fluid Framework uses this package as an implementation detail.**
|
|
12
|
+
**Do not use it as a public dependency.**
|
|
13
|
+
**We do not guarantee the stability of this package or its APIs.**
|
|
13
14
|
|
|
14
15
|
<!-- prettier-ignore-end -->
|
|
15
16
|
|
|
@@ -84,17 +85,18 @@ verifying actual exports, but the consistency of tags within the legacy API set.
|
|
|
84
85
|
|
|
85
86
|
## Contribution Guidelines
|
|
86
87
|
|
|
87
|
-
|
|
88
|
+
You can [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid Framework in these ways:
|
|
88
89
|
|
|
89
|
-
-
|
|
90
|
-
- [Submit
|
|
91
|
-
- Review
|
|
90
|
+
- Answer questions in [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
|
|
91
|
+
- [Submit bug reports](https://github.com/microsoft/FluidFramework/issues) and help verify fixes.
|
|
92
|
+
- Review [source code changes](https://github.com/microsoft/FluidFramework/pulls).
|
|
92
93
|
- [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
For detailed instructions, read the [repo documentation](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Home.md).
|
|
95
96
|
|
|
96
|
-
This project
|
|
97
|
-
For more information
|
|
97
|
+
This project follows the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
98
|
+
For more information, read the [Code of Conduct frequently asked questions](https://opensource.microsoft.com/codeofconduct/faq/).
|
|
99
|
+
For questions or comments, contact [opencode@microsoft.com](mailto:opencode@microsoft.com).
|
|
98
100
|
|
|
99
101
|
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
100
102
|
Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
|
|
@@ -102,13 +104,9 @@ Use of Microsoft trademarks or logos in modified versions of this project must n
|
|
|
102
104
|
|
|
103
105
|
## Help
|
|
104
106
|
|
|
105
|
-
|
|
106
|
-
Check out [fluidframework.com](https://fluidframework.com/docs/).
|
|
107
|
+
Read the [Fluid Framework documentation](https://fluidframework.com/docs/) for information about Fluid Framework concepts and APIs.
|
|
107
108
|
|
|
108
|
-
|
|
109
|
-
Please [file an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
|
|
110
|
-
|
|
111
|
-
Thank you!
|
|
109
|
+
To request information that the documentation does not contain, [create an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
|
|
112
110
|
|
|
113
111
|
## Trademark
|
|
114
112
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
import type { IsoBufferEncoding } from "./buffer.js";
|
|
5
6
|
/**
|
|
6
7
|
* Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string
|
|
7
8
|
* to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.
|
|
@@ -24,5 +25,5 @@ export declare const fromUtf8ToBase64: (input: string) => string;
|
|
|
24
25
|
*
|
|
25
26
|
* @internal
|
|
26
27
|
*/
|
|
27
|
-
export declare const toUtf8: (input: string, encoding:
|
|
28
|
+
export declare const toUtf8: (input: string, encoding: IsoBufferEncoding) => string;
|
|
28
29
|
//# sourceMappingURL=base64EncodingBrowser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64EncodingBrowser.d.ts","sourceRoot":"","sources":["../src/base64EncodingBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"base64EncodingBrowser.d.ts","sourceRoot":"","sources":["../src/base64EncodingBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQrD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MACA,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MACA,CAAC;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,EAAE,UAAU,iBAAiB,KAAG,MAWnE,CAAC"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.toUtf8 = exports.fromUtf8ToBase64 = exports.fromBase64ToUtf8 = void 0;
|
|
8
|
-
// This file is a
|
|
8
|
+
// This file is a browser-specific implementation of the base64 encoding functions.
|
|
9
9
|
// Aside from the below import statement, this file should be identical to the
|
|
10
10
|
// base64EncodingNode.ts.
|
|
11
11
|
//
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64EncodingBrowser.js","sourceRoot":"","sources":["../src/base64EncodingBrowser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"base64EncodingBrowser.js","sourceRoot":"","sources":["../src/base64EncodingBrowser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,mFAAmF;AACnF,8EAA8E;AAC9E,yBAAyB;AACzB,EAAE;AACF,4DAA4D;AAC5D,yDAA+C;AAE/C;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,4BAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AADrC,QAAA,gBAAgB,oBACqB;AAElD;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,4BAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AADrC,QAAA,gBAAgB,oBACqB;AAElD;;;;;;;GAOG;AACI,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,QAA2B,EAAU,EAAE;IAC5E,QAAQ,QAAQ,EAAE,CAAC;QAClB,KAAK,MAAM,CAAC;QACZ,8GAA8G;QAC9G,KAAK,OAAO,CAAC,CAAC,CAAC;YACd,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,OAAO,4BAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QACnD,CAAC;IACF,CAAC;AACF,CAAC,CAAC;AAXW,QAAA,MAAM,UAWjB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IsoBufferEncoding } from \"./buffer.js\";\n// This file is a browser-specific implementation of the base64 encoding functions.\n// Aside from the below import statement, this file should be identical to the\n// base64EncodingNode.ts.\n//\n// (See 'Isomorphic Code' section in the package README.md.)\nimport { IsoBuffer } from \"./bufferBrowser.js\";\n\n/**\n * Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string\n * to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.\n *\n * @internal\n */\nexport const fromBase64ToUtf8 = (input: string): string =>\n\tIsoBuffer.from(input, \"base64\").toString(\"utf8\");\n\n/**\n * Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string\n * to {@link https://en.wikipedia.org/wiki/Base64 | base64}.\n *\n * @internal\n */\nexport const fromUtf8ToBase64 = (input: string): string =>\n\tIsoBuffer.from(input, \"utf8\").toString(\"base64\");\n\n/**\n * Convenience function to convert unknown encoding to utf8 that avoids\n * buffer copies/encode ops when no conversion is needed.\n * @param input - The source string to convert.\n * @param encoding - The source string's encoding.\n *\n * @internal\n */\nexport const toUtf8 = (input: string, encoding: IsoBufferEncoding): string => {\n\tswitch (encoding) {\n\t\tcase \"utf8\":\n\t\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\t\tcase \"utf-8\": {\n\t\t\treturn input;\n\t\t}\n\t\tdefault: {\n\t\t\treturn IsoBuffer.from(input, encoding).toString();\n\t\t}\n\t}\n};\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
import type { IsoBufferEncoding } from "./buffer.js";
|
|
5
6
|
/**
|
|
6
7
|
* Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string
|
|
7
8
|
* to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.
|
|
@@ -24,5 +25,5 @@ export declare const fromUtf8ToBase64: (input: string) => string;
|
|
|
24
25
|
*
|
|
25
26
|
* @internal
|
|
26
27
|
*/
|
|
27
|
-
export declare const toUtf8: (input: string, encoding:
|
|
28
|
+
export declare const toUtf8: (input: string, encoding: IsoBufferEncoding) => string;
|
|
28
29
|
//# sourceMappingURL=base64EncodingNode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64EncodingNode.d.ts","sourceRoot":"","sources":["../src/base64EncodingNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"base64EncodingNode.d.ts","sourceRoot":"","sources":["../src/base64EncodingNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQrD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MACA,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MACA,CAAC;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,MAAM,EAAE,UAAU,iBAAiB,KAAG,MAWnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base64EncodingNode.js","sourceRoot":"","sources":["../src/base64EncodingNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"base64EncodingNode.js","sourceRoot":"","sources":["../src/base64EncodingNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,mFAAmF;AACnF,8EAA8E;AAC9E,4BAA4B;AAC5B,EAAE;AACF,4DAA4D;AAC5D,mDAA4C;AAE5C;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,yBAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AADrC,QAAA,gBAAgB,oBACqB;AAElD;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,yBAAS,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AADrC,QAAA,gBAAgB,oBACqB;AAElD;;;;;;;GAOG;AACI,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,QAA2B,EAAU,EAAE;IAC5E,QAAQ,QAAQ,EAAE,CAAC;QAClB,KAAK,MAAM,CAAC;QACZ,8GAA8G;QAC9G,KAAK,OAAO,CAAC,CAAC,CAAC;YACd,OAAO,KAAK,CAAC;QACd,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,OAAO,yBAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QACnD,CAAC;IACF,CAAC;AACF,CAAC,CAAC;AAXW,QAAA,MAAM,UAWjB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IsoBufferEncoding } from \"./buffer.js\";\n// This file is a Node.js-specific implementation of the base64 encoding functions.\n// Aside from the below import statement, this file should be identical to the\n// base64EncodingBrowser.ts.\n//\n// (See 'Isomorphic Code' section in the package README.md.)\nimport { IsoBuffer } from \"./bufferNode.js\";\n\n/**\n * Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string\n * to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.\n *\n * @internal\n */\nexport const fromBase64ToUtf8 = (input: string): string =>\n\tIsoBuffer.from(input, \"base64\").toString(\"utf8\");\n\n/**\n * Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string\n * to {@link https://en.wikipedia.org/wiki/Base64 | base64}.\n *\n * @internal\n */\nexport const fromUtf8ToBase64 = (input: string): string =>\n\tIsoBuffer.from(input, \"utf8\").toString(\"base64\");\n\n/**\n * Convenience function to convert unknown encoding to utf8 that avoids\n * buffer copies/encode ops when no conversion is needed.\n * @param input - The source string to convert.\n * @param encoding - The source string's encoding.\n *\n * @internal\n */\nexport const toUtf8 = (input: string, encoding: IsoBufferEncoding): string => {\n\tswitch (encoding) {\n\t\tcase \"utf8\":\n\t\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged\n\t\tcase \"utf-8\": {\n\t\t\treturn input;\n\t\t}\n\t\tdefault: {\n\t\t\treturn IsoBuffer.from(input, encoding).toString();\n\t\t}\n\t}\n};\n"]}
|
package/dist/buffer.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Declare the subset of node:Buffer functionality we want to make available instead of
|
|
7
|
+
* exposing the entirely of Node's typings. These serve as the public interface
|
|
8
|
+
* of the browser and node implementation.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Set of supported encodings for string to buffer conversion.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export type IsoBufferEncoding = "utf8" | "utf-8" | "base64";
|
|
16
|
+
/**
|
|
17
|
+
* Minimal Buffer interface for our usages in the browser or Node environments.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export interface IsoBuffer<TArrayBuffer extends ArrayBufferLike> extends Uint8Array<TArrayBuffer> {
|
|
22
|
+
/**
|
|
23
|
+
* Convert the buffer to a string.
|
|
24
|
+
* Only supports encoding the whole string (unlike the Node `Buffer` equivalent)
|
|
25
|
+
* and only utf8 and base64 encodings.
|
|
26
|
+
*
|
|
27
|
+
* @param encoding - The encoding to use.
|
|
28
|
+
*/
|
|
29
|
+
toString(encoding?: IsoBufferEncoding): string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Constructor for {@link (IsoBuffer:type)}.
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export interface IsoBufferConstructor {
|
|
37
|
+
readonly prototype: IsoBuffer<ArrayBufferLike>;
|
|
38
|
+
new (length: number): IsoBuffer<ArrayBuffer>;
|
|
39
|
+
new (array: ArrayLike<number>): IsoBuffer<ArrayBuffer>;
|
|
40
|
+
new <TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(buffer: TArrayBuffer, byteOffset?: number, length?: number): IsoBuffer<TArrayBuffer>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new `IsoBuffer` containing `string`. The `encoding` parameter identifies
|
|
43
|
+
* the character encoding to be used when converting `string` into bytes.
|
|
44
|
+
*
|
|
45
|
+
* @param string - A string to encode.
|
|
46
|
+
* @param encoding - The encoding of `string`. **Default:** `'utf8'`.
|
|
47
|
+
*
|
|
48
|
+
* @privateRemarks
|
|
49
|
+
* Node buffer.buffer.d.ts declaration:
|
|
50
|
+
* `from(string: WithImplicitCoercion<string>, encoding?: IsoBufferEncoding): Buffer<ArrayBuffer>;`
|
|
51
|
+
*/
|
|
52
|
+
from(string: string, encoding?: IsoBufferEncoding): IsoBuffer<ArrayBuffer>;
|
|
53
|
+
/**
|
|
54
|
+
* Allocates a new `IsoBuffer` using an `array` of bytes in the range `0` – `255`.
|
|
55
|
+
* Array entries outside that range will be truncated to fit into it.
|
|
56
|
+
*
|
|
57
|
+
* @param value - `Uint8Array`.
|
|
58
|
+
*
|
|
59
|
+
* @remarks
|
|
60
|
+
* This is limited to `Uint8Array` input to match Node implementation that
|
|
61
|
+
* takes `ArrayLike<number>` and returns `IsoBuffer<ArrayBuffer>`.
|
|
62
|
+
*
|
|
63
|
+
* @privateRemarks
|
|
64
|
+
* Node buffer.buffer.d.ts declaration:
|
|
65
|
+
* `from(array: WithImplicitCoercion<ArrayLike<number>>): IsoBuffer<ArrayBuffer>;`
|
|
66
|
+
*/
|
|
67
|
+
from(array: Uint8Array): IsoBuffer<ArrayBuffer>;
|
|
68
|
+
/**
|
|
69
|
+
* This creates a view of the `ArrayBuffer` without copying the underlying
|
|
70
|
+
* memory. For example, when passed a reference to the `.buffer` property of a
|
|
71
|
+
* `TypedArray` instance, the newly created `Buffer` will share the same
|
|
72
|
+
* allocated memory as the `TypedArray`'s underlying `ArrayBuffer`.
|
|
73
|
+
*
|
|
74
|
+
* @param arrayBuffer - An `ArrayBuffer`, `SharedArrayBuffer`, for example the
|
|
75
|
+
* `.buffer` property of a `TypedArray`.
|
|
76
|
+
* @param byteOffset - Index of first byte to expose. **Default:** `0`.
|
|
77
|
+
* @param length - Number of bytes to expose. **Default:**
|
|
78
|
+
* `arrayBuffer.byteLength - byteOffset`.
|
|
79
|
+
*
|
|
80
|
+
* @privateRemarks
|
|
81
|
+
* Node buffer.buffer.d.ts declaration:
|
|
82
|
+
* ```
|
|
83
|
+
* public static from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>(
|
|
84
|
+
* arrayBuffer: TArrayBuffer,
|
|
85
|
+
* byteOffset?: number,
|
|
86
|
+
* length?: number,
|
|
87
|
+
* ): Buffer<ImplicitArrayBuffer<TArrayBuffer>>;
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
from<TArrayBuffer extends ArrayBufferLike>(arrayBuffer: TArrayBuffer, byteOffset?: number, length?: number): IsoBuffer<TArrayBuffer>;
|
|
91
|
+
isBuffer(obj: unknown): obj is IsoBuffer<ArrayBufferLike>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAC1B,MAAM,GAEN,OAAO,GACP,QAAQ,CAAC;AAEZ;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,YAAY,SAAS,eAAe,CAC9D,SAAQ,UAAU,CAAC,YAAY,CAAC;IAChC;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAAC;CAC/C;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACpC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,eAAe,CAAC,CAAC;IAE/C,KAAK,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IAC7C,KAAK,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IACvD,KAAK,YAAY,SAAS,eAAe,GAAG,WAAW,EACtD,MAAM,EAAE,YAAY,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACb,SAAS,CAAC,YAAY,CAAC,CAAC;IAE3B;;;;;;;;;;OAUG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3E;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,WAAW,CAAC,CAAC;IAChD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,IAAI,CAAC,YAAY,SAAS,eAAe,EACxC,WAAW,EAAE,YAAY,EACzB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,GACb,SAAS,CAAC,YAAY,CAAC,CAAC;IAE3B,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,SAAS,CAAC,eAAe,CAAC,CAAC;CAC1D"}
|
package/dist/buffer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../src/buffer.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Declare the subset of node:Buffer functionality we want to make available instead of\n * exposing the entirely of Node's typings. These serve as the public interface\n * of the browser and node implementation.\n */\n\n/**\n * Set of supported encodings for string to buffer conversion.\n *\n * @internal\n */\nexport type IsoBufferEncoding =\n\t| \"utf8\"\n\t// eslint-disable-next-line unicorn/text-encoding-identifier-case -- \"utf-8\" value is supported, just discouraged\n\t| \"utf-8\"\n\t| \"base64\";\n\n/**\n * Minimal Buffer interface for our usages in the browser or Node environments.\n *\n * @internal\n */\nexport interface IsoBuffer<TArrayBuffer extends ArrayBufferLike>\n\textends Uint8Array<TArrayBuffer> {\n\t/**\n\t * Convert the buffer to a string.\n\t * Only supports encoding the whole string (unlike the Node `Buffer` equivalent)\n\t * and only utf8 and base64 encodings.\n\t *\n\t * @param encoding - The encoding to use.\n\t */\n\ttoString(encoding?: IsoBufferEncoding): string;\n}\n\n/**\n * Constructor for {@link (IsoBuffer:type)}.\n *\n * @internal\n */\nexport interface IsoBufferConstructor {\n\treadonly prototype: IsoBuffer<ArrayBufferLike>;\n\n\tnew (length: number): IsoBuffer<ArrayBuffer>;\n\tnew (array: ArrayLike<number>): IsoBuffer<ArrayBuffer>;\n\tnew <TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(\n\t\tbuffer: TArrayBuffer,\n\t\tbyteOffset?: number,\n\t\tlength?: number,\n\t): IsoBuffer<TArrayBuffer>;\n\n\t/**\n\t * Creates a new `IsoBuffer` containing `string`. The `encoding` parameter identifies\n\t * the character encoding to be used when converting `string` into bytes.\n\t *\n\t * @param string - A string to encode.\n\t * @param encoding - The encoding of `string`. **Default:** `'utf8'`.\n\t *\n\t * @privateRemarks\n\t * Node buffer.buffer.d.ts declaration:\n\t * `from(string: WithImplicitCoercion<string>, encoding?: IsoBufferEncoding): Buffer<ArrayBuffer>;`\n\t */\n\tfrom(string: string, encoding?: IsoBufferEncoding): IsoBuffer<ArrayBuffer>;\n\t/**\n\t * Allocates a new `IsoBuffer` using an `array` of bytes in the range `0` – `255`.\n\t * Array entries outside that range will be truncated to fit into it.\n\t *\n\t * @param value - `Uint8Array`.\n\t *\n\t * @remarks\n\t * This is limited to `Uint8Array` input to match Node implementation that\n\t * takes `ArrayLike<number>` and returns `IsoBuffer<ArrayBuffer>`.\n\t *\n\t * @privateRemarks\n\t * Node buffer.buffer.d.ts declaration:\n\t * `from(array: WithImplicitCoercion<ArrayLike<number>>): IsoBuffer<ArrayBuffer>;`\n\t */\n\tfrom(array: Uint8Array): IsoBuffer<ArrayBuffer>;\n\t/**\n\t * This creates a view of the `ArrayBuffer` without copying the underlying\n\t * memory. For example, when passed a reference to the `.buffer` property of a\n\t * `TypedArray` instance, the newly created `Buffer` will share the same\n\t * allocated memory as the `TypedArray`'s underlying `ArrayBuffer`.\n\t *\n\t * @param arrayBuffer - An `ArrayBuffer`, `SharedArrayBuffer`, for example the\n\t * `.buffer` property of a `TypedArray`.\n\t * @param byteOffset - Index of first byte to expose. **Default:** `0`.\n\t * @param length - Number of bytes to expose. **Default:**\n\t * `arrayBuffer.byteLength - byteOffset`.\n\t *\n\t * @privateRemarks\n\t * Node buffer.buffer.d.ts declaration:\n\t * ```\n\t * public static from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>(\n\t * \t\tarrayBuffer: TArrayBuffer,\n\t * \t\tbyteOffset?: number,\n\t * \t\tlength?: number,\n\t * ): Buffer<ImplicitArrayBuffer<TArrayBuffer>>;\n\t * ```\n\t */\n\tfrom<TArrayBuffer extends ArrayBufferLike>(\n\t\tarrayBuffer: TArrayBuffer,\n\t\tbyteOffset?: number,\n\t\tlength?: number,\n\t): IsoBuffer<TArrayBuffer>;\n\n\tisBuffer(obj: unknown): obj is IsoBuffer<ArrayBufferLike>;\n}\n"]}
|
package/dist/bufferBrowser.d.ts
CHANGED
|
@@ -2,9 +2,20 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
+
import type { IsoBufferConstructor, IsoBufferEncoding, IsoBuffer as IsoBufferInterface } from "./buffer.js";
|
|
6
|
+
export type { IsoBufferConstructor, IsoBufferEncoding, } from "./buffer.js";
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* Minimal `Buffer` interface for our usages in the browser or Node.js environments.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*
|
|
12
|
+
* @privateRemarks
|
|
13
|
+
* This type is exported specifically from here to respect combo type+value of same name rules.
|
|
14
|
+
*/
|
|
15
|
+
export type IsoBuffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> = IsoBufferInterface<TArrayBuffer>;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a `Uint8Array` to a string of the provided encoding
|
|
18
|
+
* Useful when the array might be an {@link (IsoBuffer:type)}.
|
|
8
19
|
*
|
|
9
20
|
* @param arr - The array to convert.
|
|
10
21
|
* @param encoding - Optional target encoding; only "utf8" and "base64" are
|
|
@@ -13,7 +24,7 @@
|
|
|
13
24
|
*
|
|
14
25
|
* @internal
|
|
15
26
|
*/
|
|
16
|
-
export declare function Uint8ArrayToString(arr: Uint8Array, encoding?:
|
|
27
|
+
export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: IsoBufferEncoding): string;
|
|
17
28
|
/**
|
|
18
29
|
* Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or
|
|
19
30
|
* {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.
|
|
@@ -22,7 +33,7 @@ export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: "utf8" |
|
|
|
22
33
|
*
|
|
23
34
|
* @internal
|
|
24
35
|
*/
|
|
25
|
-
export declare const stringToBuffer: (input: string, encoding:
|
|
36
|
+
export declare const stringToBuffer: (input: string, encoding: IsoBufferEncoding) => ArrayBuffer;
|
|
26
37
|
/**
|
|
27
38
|
* Convert binary blob to string format
|
|
28
39
|
*
|
|
@@ -32,53 +43,11 @@ export declare const stringToBuffer: (input: string, encoding: string) => ArrayB
|
|
|
32
43
|
*
|
|
33
44
|
* @internal
|
|
34
45
|
*/
|
|
35
|
-
export declare const bufferToString: (blob: ArrayBufferLike, encoding:
|
|
36
|
-
/**
|
|
37
|
-
* Determines if an object is an array buffer.
|
|
38
|
-
*
|
|
39
|
-
* @remarks Will detect and reject TypedArrays, like Uint8Array.
|
|
40
|
-
* Reason - they can be viewport into Array, they can be accepted, but caller has to deal with
|
|
41
|
-
* math properly (i.e. Take into account byteOffset at minimum).
|
|
42
|
-
* For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or
|
|
43
|
-
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and
|
|
44
|
-
* ignoring byteOffice, length).
|
|
45
|
-
*
|
|
46
|
-
* @param obj - The object to determine if it is an ArrayBuffer.
|
|
47
|
-
*
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
50
|
-
export declare function isArrayBuffer(obj: unknown): obj is ArrayBuffer;
|
|
46
|
+
export declare const bufferToString: (blob: ArrayBufferLike | Uint8Array, encoding: IsoBufferEncoding) => string;
|
|
51
47
|
/**
|
|
52
|
-
* Minimal implementation of Buffer for our usages in the browser environment.
|
|
48
|
+
* Minimal implementation of `Buffer` for our usages in the browser environment.
|
|
53
49
|
*
|
|
54
50
|
* @internal
|
|
55
51
|
*/
|
|
56
|
-
export declare
|
|
57
|
-
/**
|
|
58
|
-
* Convert the buffer to a string.
|
|
59
|
-
* Only supports encoding the whole string (unlike the Node Buffer equivalent)
|
|
60
|
-
* and only utf8 and base64 encodings.
|
|
61
|
-
*
|
|
62
|
-
* @param encoding - The encoding to use.
|
|
63
|
-
*/
|
|
64
|
-
toString(encoding?: "utf8" | "utf-8" | "base64"): string;
|
|
65
|
-
/**
|
|
66
|
-
* Static constructor
|
|
67
|
-
* @param value - (string | ArrayBuffer)
|
|
68
|
-
* @param encodingOrOffset - (string | number)
|
|
69
|
-
* @param length - (number)
|
|
70
|
-
*
|
|
71
|
-
* @privateRemarks TODO: Use actual types
|
|
72
|
-
*/
|
|
73
|
-
static from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer;
|
|
74
|
-
static fromArrayBuffer(arrayBuffer: ArrayBuffer, byteOffset?: number, byteLength?: number): IsoBuffer;
|
|
75
|
-
static fromString(str: string, encoding?: string): IsoBuffer;
|
|
76
|
-
static isBuffer(obj: unknown): boolean;
|
|
77
|
-
/**
|
|
78
|
-
* Sanitize a base64 string to provide to base64-js library.
|
|
79
|
-
* {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'
|
|
80
|
-
* Buffer is.
|
|
81
|
-
*/
|
|
82
|
-
private static sanitizeBase64;
|
|
83
|
-
}
|
|
52
|
+
export declare const IsoBuffer: IsoBufferConstructor;
|
|
84
53
|
//# sourceMappingURL=bufferBrowser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bufferBrowser.d.ts","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH
|
|
1
|
+
{"version":3,"file":"bufferBrowser.d.ts","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EACX,oBAAoB,EACpB,iBAAiB,EACjB,SAAS,IAAI,kBAAkB,EAC/B,MAAM,aAAa,CAAC;AAErB,YAAY,EACX,oBAAoB,EACpB,iBAAiB,GACjB,MAAM,aAAa,CAAC;AACrB;;;;;;;GAOG;AACH,MAAM,MAAM,SAAS,CAAC,YAAY,SAAS,eAAe,GAAG,eAAe,IAC3E,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAElC;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAexF;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,EAAE,UAAU,iBAAiB,KAAG,WACrC,CAAC;AAExC;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAC1B,MAAM,eAAe,GAAG,UAAU,EAClC,UAAU,iBAAiB,KACzB,MACoF,CAAC;AAiCxF;;;;GAIG;AAEH,eAAO,MAAM,SAAS,EAAE,oBA8HQ,CAAC"}
|
package/dist/bufferBrowser.js
CHANGED
|
@@ -19,19 +19,30 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
19
19
|
}) : function(o, v) {
|
|
20
20
|
o["default"] = v;
|
|
21
21
|
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || function (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
29
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.IsoBuffer = exports.
|
|
40
|
+
exports.IsoBuffer = exports.bufferToString = exports.stringToBuffer = void 0;
|
|
41
|
+
exports.Uint8ArrayToString = Uint8ArrayToString;
|
|
31
42
|
const base64js = __importStar(require("base64-js"));
|
|
32
43
|
/**
|
|
33
|
-
* Converts a Uint8Array to a string of the provided encoding
|
|
34
|
-
* Useful when the array might be an {@link IsoBuffer}.
|
|
44
|
+
* Converts a `Uint8Array` to a string of the provided encoding
|
|
45
|
+
* Useful when the array might be an {@link (IsoBuffer:type)}.
|
|
35
46
|
*
|
|
36
47
|
* @param arr - The array to convert.
|
|
37
48
|
* @param encoding - Optional target encoding; only "utf8" and "base64" are
|
|
@@ -40,9 +51,7 @@ const base64js = __importStar(require("base64-js"));
|
|
|
40
51
|
*
|
|
41
52
|
* @internal
|
|
42
53
|
*/
|
|
43
|
-
function Uint8ArrayToString(arr,
|
|
44
|
-
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
45
|
-
encoding) {
|
|
54
|
+
function Uint8ArrayToString(arr, encoding) {
|
|
46
55
|
switch (encoding) {
|
|
47
56
|
case "base64": {
|
|
48
57
|
return base64js.fromByteArray(arr);
|
|
@@ -58,7 +67,6 @@ encoding) {
|
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
|
-
exports.Uint8ArrayToString = Uint8ArrayToString;
|
|
62
70
|
/**
|
|
63
71
|
* Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or
|
|
64
72
|
* {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.
|
|
@@ -67,7 +75,7 @@ exports.Uint8ArrayToString = Uint8ArrayToString;
|
|
|
67
75
|
*
|
|
68
76
|
* @internal
|
|
69
77
|
*/
|
|
70
|
-
const stringToBuffer = (input, encoding) => IsoBuffer.from(input, encoding).buffer;
|
|
78
|
+
const stringToBuffer = (input, encoding) => exports.IsoBuffer.from(input, encoding).buffer;
|
|
71
79
|
exports.stringToBuffer = stringToBuffer;
|
|
72
80
|
/**
|
|
73
81
|
* Convert binary blob to string format
|
|
@@ -78,9 +86,7 @@ exports.stringToBuffer = stringToBuffer;
|
|
|
78
86
|
*
|
|
79
87
|
* @internal
|
|
80
88
|
*/
|
|
81
|
-
const bufferToString = (blob,
|
|
82
|
-
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
83
|
-
encoding) => IsoBuffer.from(blob).toString(encoding);
|
|
89
|
+
const bufferToString = (blob, encoding) => Uint8ArrayToString(blob instanceof Uint8Array ? blob : exports.IsoBuffer.from(blob), encoding);
|
|
84
90
|
exports.bufferToString = bufferToString;
|
|
85
91
|
/**
|
|
86
92
|
* Determines if an object is an array buffer.
|
|
@@ -92,11 +98,15 @@ exports.bufferToString = bufferToString;
|
|
|
92
98
|
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and
|
|
93
99
|
* ignoring byteOffice, length).
|
|
94
100
|
*
|
|
95
|
-
* @param obj - The object to determine if it is
|
|
101
|
+
* @param obj - The object to determine if it is `ArrayBufferLike`.
|
|
96
102
|
*
|
|
97
|
-
* @
|
|
103
|
+
* @privateRemarks
|
|
104
|
+
* This function preserves runtime functionality as it has been in the past.
|
|
105
|
+
* Typing has been adjusted to reflect the only use that remains and (assuming
|
|
106
|
+
* is called as expected) will always return true as the input is already
|
|
107
|
+
* expected to be `ArrayBufferLike`.
|
|
98
108
|
*/
|
|
99
|
-
function
|
|
109
|
+
function isArrayBufferLike(obj) {
|
|
100
110
|
const maybe = obj;
|
|
101
111
|
return (obj instanceof ArrayBuffer ||
|
|
102
112
|
(typeof maybe === "object" &&
|
|
@@ -106,51 +116,37 @@ function isArrayBuffer(obj) {
|
|
|
106
116
|
maybe.byteOffset === undefined &&
|
|
107
117
|
maybe.buffer === undefined));
|
|
108
118
|
}
|
|
109
|
-
exports.isArrayBuffer = isArrayBuffer;
|
|
110
119
|
/**
|
|
111
|
-
* Minimal implementation of Buffer for our usages in the browser environment.
|
|
120
|
+
* Minimal implementation of `Buffer` for our usages in the browser environment.
|
|
112
121
|
*
|
|
113
122
|
* @internal
|
|
114
123
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
* @param encoding - The encoding to use.
|
|
122
|
-
*/
|
|
123
|
-
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow -- Preserve the public constructor name at runtime.
|
|
125
|
+
exports.IsoBuffer = class IsoBuffer extends Uint8Array {
|
|
126
|
+
constructor(value, byteOffset, length) {
|
|
127
|
+
super(value, byteOffset, length);
|
|
128
|
+
}
|
|
124
129
|
toString(encoding) {
|
|
125
130
|
return Uint8ArrayToString(this, encoding);
|
|
126
131
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Static constructor
|
|
129
|
-
* @param value - (string | ArrayBuffer)
|
|
130
|
-
* @param encodingOrOffset - (string | number)
|
|
131
|
-
* @param length - (number)
|
|
132
|
-
*
|
|
133
|
-
* @privateRemarks TODO: Use actual types
|
|
134
|
-
*/
|
|
135
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
136
132
|
static from(value, encodingOrOffset, length) {
|
|
137
133
|
if (typeof value === "string") {
|
|
138
134
|
return IsoBuffer.fromString(value, encodingOrOffset);
|
|
139
135
|
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)
|
|
140
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
141
136
|
}
|
|
142
|
-
else if (value
|
|
137
|
+
else if (value instanceof Uint8Array) {
|
|
143
138
|
// The version of the from function for the node buffer, which takes a buffer or typed array
|
|
144
139
|
// as first parameter, does not have any offset or length parameters. Those are just silently
|
|
145
140
|
// ignored and not taken into account
|
|
146
|
-
|
|
147
|
-
|
|
141
|
+
const copy = new Uint8Array(value.byteLength);
|
|
142
|
+
copy.set(value);
|
|
143
|
+
return new IsoBuffer(copy.buffer);
|
|
148
144
|
}
|
|
149
|
-
else if (
|
|
145
|
+
else if (isArrayBufferLike(value)) {
|
|
150
146
|
return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length);
|
|
151
147
|
}
|
|
152
148
|
else {
|
|
153
|
-
throw new TypeError("Input value was neither a string nor an ArrayBuffer.");
|
|
149
|
+
throw new TypeError("Input value was neither a string, a Uint8Array, nor an ArrayBuffer.");
|
|
154
150
|
}
|
|
155
151
|
}
|
|
156
152
|
static fromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
|
|
@@ -168,15 +164,17 @@ class IsoBuffer extends Uint8Array {
|
|
|
168
164
|
switch (encoding) {
|
|
169
165
|
case "base64": {
|
|
170
166
|
const sanitizedString = this.sanitizeBase64(str);
|
|
167
|
+
// base64-js will always return a Uint8Array<ArrayBuffer>, but typing has not
|
|
168
|
+
// been updated to reflect that yet. Cast to the correct type here.
|
|
171
169
|
const encoded = base64js.toByteArray(sanitizedString);
|
|
172
|
-
return new IsoBuffer(encoded.buffer);
|
|
170
|
+
return new IsoBuffer(encoded.buffer, encoded.byteOffset, encoded.byteLength);
|
|
173
171
|
}
|
|
174
172
|
case "utf8":
|
|
175
173
|
// eslint-disable-next-line unicorn/text-encoding-identifier-case -- this value is supported, just discouraged
|
|
176
174
|
case "utf-8":
|
|
177
175
|
case undefined: {
|
|
178
176
|
const encoded = new TextEncoder().encode(str);
|
|
179
|
-
return new IsoBuffer(encoded.buffer);
|
|
177
|
+
return new IsoBuffer(encoded.buffer, encoded.byteOffset, encoded.byteLength);
|
|
180
178
|
}
|
|
181
179
|
default: {
|
|
182
180
|
throw new Error("invalid/unsupported encoding");
|
|
@@ -184,7 +182,7 @@ class IsoBuffer extends Uint8Array {
|
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
184
|
static isBuffer(obj) {
|
|
187
|
-
|
|
185
|
+
return obj instanceof IsoBuffer;
|
|
188
186
|
}
|
|
189
187
|
/**
|
|
190
188
|
* Sanitize a base64 string to provide to base64-js library.
|
|
@@ -207,6 +205,5 @@ class IsoBuffer extends Uint8Array {
|
|
|
207
205
|
}
|
|
208
206
|
return sanitizedStr;
|
|
209
207
|
}
|
|
210
|
-
}
|
|
211
|
-
exports.IsoBuffer = IsoBuffer;
|
|
208
|
+
};
|
|
212
209
|
//# sourceMappingURL=bufferBrowser.js.map
|