@fluid-internal/client-utils 2.0.0-internal.6.3.1
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/.eslintrc.js +20 -0
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +3 -0
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/api-extractor.json +16 -0
- package/dist/base64Encoding.d.ts +28 -0
- package/dist/base64Encoding.d.ts.map +1 -0
- package/dist/base64Encoding.js +43 -0
- package/dist/base64Encoding.js.map +1 -0
- package/dist/bufferBrowser.d.ts +81 -0
- package/dist/bufferBrowser.d.ts.map +1 -0
- package/dist/bufferBrowser.js +195 -0
- package/dist/bufferBrowser.js.map +1 -0
- package/dist/bufferNode.d.ts +58 -0
- package/dist/bufferNode.d.ts.map +1 -0
- package/dist/bufferNode.js +54 -0
- package/dist/bufferNode.js.map +1 -0
- package/dist/bufferShared.d.ts +12 -0
- package/dist/bufferShared.d.ts.map +1 -0
- package/dist/bufferShared.js +21 -0
- package/dist/bufferShared.js.map +1 -0
- package/dist/eventForwarder.d.ts +33 -0
- package/dist/eventForwarder.d.ts.map +1 -0
- package/dist/eventForwarder.js +98 -0
- package/dist/eventForwarder.js.map +1 -0
- package/dist/hashFileBrowser.d.ts +30 -0
- package/dist/hashFileBrowser.d.ts.map +1 -0
- package/dist/hashFileBrowser.js +95 -0
- package/dist/hashFileBrowser.js.map +1 -0
- package/dist/hashFileNode.d.ts +30 -0
- package/dist/hashFileNode.d.ts.map +1 -0
- package/dist/hashFileNode.js +60 -0
- package/dist/hashFileNode.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/indexBrowser.d.ts +8 -0
- package/dist/indexBrowser.d.ts.map +1 -0
- package/dist/indexBrowser.js +19 -0
- package/dist/indexBrowser.js.map +1 -0
- package/dist/indexNode.d.ts +8 -0
- package/dist/indexNode.d.ts.map +1 -0
- package/dist/indexNode.js +19 -0
- package/dist/indexNode.js.map +1 -0
- package/dist/performanceBrowser.d.ts +10 -0
- package/dist/performanceBrowser.d.ts.map +1 -0
- package/dist/performanceBrowser.js +12 -0
- package/dist/performanceBrowser.js.map +1 -0
- package/dist/performanceIsomorphic.d.ts +12 -0
- package/dist/performanceIsomorphic.d.ts.map +1 -0
- package/dist/performanceIsomorphic.js +7 -0
- package/dist/performanceIsomorphic.js.map +1 -0
- package/dist/performanceNode.d.ts +10 -0
- package/dist/performanceNode.d.ts.map +1 -0
- package/dist/performanceNode.js +14 -0
- package/dist/performanceNode.js.map +1 -0
- package/dist/trace.d.ts +40 -0
- package/dist/trace.d.ts.map +1 -0
- package/dist/trace.js +36 -0
- package/dist/trace.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/typedEventEmitter.d.ts +37 -0
- package/dist/typedEventEmitter.d.ts.map +1 -0
- package/dist/typedEventEmitter.js +27 -0
- package/dist/typedEventEmitter.js.map +1 -0
- package/jest-puppeteer.config.js +13 -0
- package/jest.config.js +20 -0
- package/lib/base64Encoding.d.ts +28 -0
- package/lib/base64Encoding.d.ts.map +1 -0
- package/lib/base64Encoding.js +37 -0
- package/lib/base64Encoding.js.map +1 -0
- package/lib/bufferBrowser.d.ts +81 -0
- package/lib/bufferBrowser.d.ts.map +1 -0
- package/lib/bufferBrowser.js +168 -0
- package/lib/bufferBrowser.js.map +1 -0
- package/lib/bufferNode.d.ts +58 -0
- package/lib/bufferNode.d.ts.map +1 -0
- package/lib/bufferNode.js +48 -0
- package/lib/bufferNode.js.map +1 -0
- package/lib/bufferShared.d.ts +12 -0
- package/lib/bufferShared.d.ts.map +1 -0
- package/lib/bufferShared.js +17 -0
- package/lib/bufferShared.js.map +1 -0
- package/lib/eventForwarder.d.ts +33 -0
- package/lib/eventForwarder.d.ts.map +1 -0
- package/lib/eventForwarder.js +94 -0
- package/lib/eventForwarder.js.map +1 -0
- package/lib/hashFileBrowser.d.ts +30 -0
- package/lib/hashFileBrowser.d.ts.map +1 -0
- package/lib/hashFileBrowser.js +71 -0
- package/lib/hashFileBrowser.js.map +1 -0
- package/lib/hashFileNode.d.ts +30 -0
- package/lib/hashFileNode.d.ts.map +1 -0
- package/lib/hashFileNode.js +52 -0
- package/lib/hashFileNode.js.map +1 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/indexBrowser.d.ts +8 -0
- package/lib/indexBrowser.d.ts.map +1 -0
- package/lib/indexBrowser.js +8 -0
- package/lib/indexBrowser.js.map +1 -0
- package/lib/indexNode.d.ts +8 -0
- package/lib/indexNode.d.ts.map +1 -0
- package/lib/indexNode.js +8 -0
- package/lib/indexNode.js.map +1 -0
- package/lib/performanceBrowser.d.ts +10 -0
- package/lib/performanceBrowser.d.ts.map +1 -0
- package/lib/performanceBrowser.js +9 -0
- package/lib/performanceBrowser.js.map +1 -0
- package/lib/performanceIsomorphic.d.ts +12 -0
- package/lib/performanceIsomorphic.d.ts.map +1 -0
- package/lib/performanceIsomorphic.js +6 -0
- package/lib/performanceIsomorphic.js.map +1 -0
- package/lib/performanceNode.d.ts +10 -0
- package/lib/performanceNode.d.ts.map +1 -0
- package/lib/performanceNode.js +11 -0
- package/lib/performanceNode.js.map +1 -0
- package/lib/trace.d.ts +40 -0
- package/lib/trace.d.ts.map +1 -0
- package/lib/trace.js +32 -0
- package/lib/trace.js.map +1 -0
- package/lib/typedEventEmitter.d.ts +37 -0
- package/lib/typedEventEmitter.d.ts.map +1 -0
- package/lib/typedEventEmitter.js +23 -0
- package/lib/typedEventEmitter.js.map +1 -0
- package/package.json +140 -0
- package/prettier.config.cjs +8 -0
- package/src/base64Encoding.ts +42 -0
- package/src/bufferBrowser.ts +188 -0
- package/src/bufferNode.ts +75 -0
- package/src/bufferShared.ts +17 -0
- package/src/eventForwarder.ts +120 -0
- package/src/hashFileBrowser.ts +82 -0
- package/src/hashFileNode.ts +59 -0
- package/src/index.ts +22 -0
- package/src/indexBrowser.ts +14 -0
- package/src/indexNode.ts +14 -0
- package/src/performanceBrowser.ts +11 -0
- package/src/performanceIsomorphic.ts +13 -0
- package/src/performanceNode.ts +13 -0
- package/src/trace.ts +58 -0
- package/src/typedEventEmitter.ts +76 -0
- package/tsconfig.esnext.json +7 -0
- package/tsconfig.json +14 -0
- package/types/perf_hooks.d.ts +10 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
|
|
8
|
+
parserOptions: {
|
|
9
|
+
project: [
|
|
10
|
+
"./tsconfig.json",
|
|
11
|
+
"./src/test/mocha/tsconfig.json",
|
|
12
|
+
"./src/test/jest/tsconfig.json",
|
|
13
|
+
"./src/test/types/tsconfig.json",
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
rules: {
|
|
17
|
+
// TODO: Remove once this config extends `recommended` or `strict` above.
|
|
18
|
+
"@typescript-eslint/explicit-function-return-type": "error",
|
|
19
|
+
},
|
|
20
|
+
};
|
package/.mocharc.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const getFluidTestMochaConfig = require("@fluidframework/mocha-test-setup/mocharc-common");
|
|
9
|
+
|
|
10
|
+
const packageDir = __dirname;
|
|
11
|
+
const config = getFluidTestMochaConfig(packageDir);
|
|
12
|
+
module.exports = config;
|
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @fluid-internal/client-utils
|
|
2
|
+
|
|
3
|
+
This package is intended for sharing and promoting utility functions across packages in the Fluid Framework repo,
|
|
4
|
+
primarily within the client release group.
|
|
5
|
+
|
|
6
|
+
Use outside of the Fluid Framework repo is not supported or recommended.
|
|
7
|
+
|
|
8
|
+
## Adding code to this package
|
|
9
|
+
|
|
10
|
+
As a utility package, this package does not have a strong identity. This means that it's easy to become a "dumping
|
|
11
|
+
ground" for code that we think we should share but doesn't have an obvious home. We try to avoid dumping things into
|
|
12
|
+
utility packages, and this one is no exception.
|
|
13
|
+
|
|
14
|
+
New code should only be added to this package in rare circumstances. In most cases, the code would be better placed in a
|
|
15
|
+
package with a clear identity (e.g. an "events" package for shared event infrastructure) or not shared at all.
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
This package has important requirements for the code within it.
|
|
20
|
+
|
|
21
|
+
1. Code within this package should require some external dependencies. If it does not, then the **core-utils** package
|
|
22
|
+
is a better location.
|
|
23
|
+
1. **All exports must be designated `@internal`.** This code is intended for use within the Fluid Framework only.
|
|
24
|
+
1. This package should **only contain 'implementation' code, not type definitions.** This is the most flexible rule, and
|
|
25
|
+
there are some exceptions. If the type is _only_ necessary when using this package, then it is probably OK. However,
|
|
26
|
+
usually such types would be better placed in core-interfaces or in a package that corresponds to the purpose.
|
|
27
|
+
|
|
28
|
+
If you want to add code that does not meet these requirements, these other packages may be a better choice:
|
|
29
|
+
|
|
30
|
+
- **Types and interfaces** that are intended to be broadly shared across the client release group should be put in the
|
|
31
|
+
**core-interfaces** package.
|
|
32
|
+
- **Zero-dependency shared code** should be put in the **core-utils** package.
|
|
33
|
+
|
|
34
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_DEPENDENCY_GUIDELINES_SECTION:includeHeading=TRUE) -->
|
|
35
|
+
|
|
36
|
+
<!-- prettier-ignore-start -->
|
|
37
|
+
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
38
|
+
|
|
39
|
+
## Using Fluid Framework libraries
|
|
40
|
+
|
|
41
|
+
When taking a dependency on a Fluid Framework library, we recommend using a `^` (caret) version range, such as `^1.3.4`.
|
|
42
|
+
While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
|
|
43
|
+
library consumers should always prefer `^`.
|
|
44
|
+
|
|
45
|
+
Note that when depending on a library version of the form 2.0.0-internal.x.y.z, called the Fluid internal version
|
|
46
|
+
scheme, you must use a `>= <` dependency range. Standard `^` and `~` ranges will not work as expected. See the
|
|
47
|
+
[@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
|
|
48
|
+
package for more information including tools to convert between version schemes.
|
|
49
|
+
|
|
50
|
+
<!-- prettier-ignore-end -->
|
|
51
|
+
|
|
52
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
53
|
+
|
|
54
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_TRADEMARK_SECTION:includeHeading=TRUE) -->
|
|
55
|
+
|
|
56
|
+
<!-- prettier-ignore-start -->
|
|
57
|
+
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
58
|
+
|
|
59
|
+
## Trademark
|
|
60
|
+
|
|
61
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
62
|
+
|
|
63
|
+
Use of these trademarks or logos must follow Microsoft's [Trademark & Brand
|
|
64
|
+
Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
|
65
|
+
|
|
66
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
67
|
+
|
|
68
|
+
<!-- prettier-ignore-end -->
|
|
69
|
+
|
|
70
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "@fluidframework/build-common/api-extractor-common-report.json",
|
|
4
|
+
"messages": {
|
|
5
|
+
"extractorMessageReporting": {
|
|
6
|
+
"ae-missing-release-tag": {
|
|
7
|
+
"logLevel": "error",
|
|
8
|
+
"addToApiReportFile": false
|
|
9
|
+
},
|
|
10
|
+
"ae-incompatible-release-tags": {
|
|
11
|
+
"logLevel": "error",
|
|
12
|
+
"addToApiReportFile": false
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string
|
|
7
|
+
* to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare const fromBase64ToUtf8: (input: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string
|
|
14
|
+
* to {@link https://en.wikipedia.org/wiki/Base64 | base64}.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare const fromUtf8ToBase64: (input: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* Convenience function to convert unknown encoding to utf8 that avoids
|
|
21
|
+
* buffer copies/encode ops when no conversion is needed.
|
|
22
|
+
* @param input - The source string to convert.
|
|
23
|
+
* @param encoding - The source string's encoding.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export declare const toUtf8: (input: string, encoding: string) => string;
|
|
28
|
+
//# sourceMappingURL=base64Encoding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64Encoding.d.ts","sourceRoot":"","sources":["../src/base64Encoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,MACC,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,MACA,CAAC;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,UAAW,MAAM,YAAY,MAAM,KAAG,MAQxD,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.toUtf8 = exports.fromUtf8ToBase64 = exports.fromBase64ToUtf8 = void 0;
|
|
8
|
+
const indexNode_1 = require("./indexNode");
|
|
9
|
+
/**
|
|
10
|
+
* Converts the provided {@link https://en.wikipedia.org/wiki/Base64 | base64}-encoded string
|
|
11
|
+
* to {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
const fromBase64ToUtf8 = (input) => indexNode_1.IsoBuffer.from(input, "base64").toString("utf-8");
|
|
16
|
+
exports.fromBase64ToUtf8 = fromBase64ToUtf8;
|
|
17
|
+
/**
|
|
18
|
+
* Converts the provided {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8}-encoded string
|
|
19
|
+
* to {@link https://en.wikipedia.org/wiki/Base64 | base64}.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
const fromUtf8ToBase64 = (input) => indexNode_1.IsoBuffer.from(input, "utf8").toString("base64");
|
|
24
|
+
exports.fromUtf8ToBase64 = fromUtf8ToBase64;
|
|
25
|
+
/**
|
|
26
|
+
* Convenience function to convert unknown encoding to utf8 that avoids
|
|
27
|
+
* buffer copies/encode ops when no conversion is needed.
|
|
28
|
+
* @param input - The source string to convert.
|
|
29
|
+
* @param encoding - The source string's encoding.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
const toUtf8 = (input, encoding) => {
|
|
34
|
+
switch (encoding) {
|
|
35
|
+
case "utf8":
|
|
36
|
+
case "utf-8":
|
|
37
|
+
return input;
|
|
38
|
+
default:
|
|
39
|
+
return indexNode_1.IsoBuffer.from(input, encoding).toString();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.toUtf8 = toUtf8;
|
|
43
|
+
//# sourceMappingURL=base64Encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64Encoding.js","sourceRoot":"","sources":["../src/base64Encoding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAAwC;AAExC;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,qBAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AADtC,QAAA,gBAAgB,oBACsB;AAEnD;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAU,EAAE,CACzD,qBAAS,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,QAAgB,EAAU,EAAE;IACjE,QAAQ,QAAQ,EAAE;QACjB,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO;YACX,OAAO,KAAK,CAAC;QACd;YACC,OAAO,qBAAS,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;KACnD;AACF,CAAC,CAAC;AARW,QAAA,MAAM,UAQjB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IsoBuffer } from \"./indexNode\";\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(\"utf-8\");\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: string): string => {\n\tswitch (encoding) {\n\t\tcase \"utf8\":\n\t\tcase \"utf-8\":\n\t\t\treturn input;\n\t\tdefault:\n\t\t\treturn IsoBuffer.from(input, encoding).toString();\n\t}\n};\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Converts a Uint8Array to a string of the provided encoding
|
|
7
|
+
* Useful when the array might be an {@link IsoBuffer}.
|
|
8
|
+
*
|
|
9
|
+
* @param arr - The array to convert.
|
|
10
|
+
* @param encoding - Optional target encoding; only "utf8" and "base64" are
|
|
11
|
+
* supported, with "utf8" being default.
|
|
12
|
+
* @returns The converted string.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or
|
|
19
|
+
* {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.
|
|
20
|
+
*
|
|
21
|
+
* @param encoding - The input string's encoding.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare const stringToBuffer: (input: string, encoding: string) => ArrayBufferLike;
|
|
26
|
+
/**
|
|
27
|
+
* Convert binary blob to string format
|
|
28
|
+
*
|
|
29
|
+
* @param blob - the binary blob
|
|
30
|
+
* @param encoding - output string's encoding
|
|
31
|
+
* @returns the blob in string format
|
|
32
|
+
*
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare const bufferToString: (blob: ArrayBufferLike, encoding: string) => string;
|
|
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: any): obj is ArrayBuffer;
|
|
51
|
+
/**
|
|
52
|
+
* Minimal implementation of Buffer for our usages in the browser environment.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export declare class IsoBuffer extends Uint8Array {
|
|
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?: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* @param value - (string | ArrayBuffer)
|
|
67
|
+
* @param encodingOrOffset - (string | number)
|
|
68
|
+
* @param length - (number)
|
|
69
|
+
*/
|
|
70
|
+
static from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer;
|
|
71
|
+
static fromArrayBuffer(arrayBuffer: ArrayBuffer, byteOffset?: number, byteLength?: number): IsoBuffer;
|
|
72
|
+
static fromString(str: string, encoding?: string): IsoBuffer;
|
|
73
|
+
static isBuffer(obj: any): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Sanitize a base64 string to provide to base64-js library.
|
|
76
|
+
* {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'
|
|
77
|
+
* Buffer is.
|
|
78
|
+
*/
|
|
79
|
+
private static sanitizeBase64;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=bufferBrowser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferBrowser.d.ts","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAc7E;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,UAAW,MAAM,YAAY,MAAM,KAAG,eAC1B,CAAC;AAExC;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,SAAU,eAAe,YAAY,MAAM,KAAG,MACjC,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,CAW1D;AAED;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACxC;;;;;;OAMG;IACI,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAI1C;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,KAAA,EAAE,gBAAgB,CAAC,KAAA,EAAE,MAAM,CAAC,KAAA,GAAG,SAAS;IAgBzD,MAAM,CAAC,eAAe,CACrB,WAAW,EAAE,WAAW,EACxB,UAAU,CAAC,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GACjB,SAAS;IAeZ,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS;IAmB5D,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAIlC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,cAAc;CAkB7B"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.IsoBuffer = exports.isArrayBuffer = exports.bufferToString = exports.stringToBuffer = exports.Uint8ArrayToString = void 0;
|
|
27
|
+
const base64js = __importStar(require("base64-js"));
|
|
28
|
+
/**
|
|
29
|
+
* Converts a Uint8Array to a string of the provided encoding
|
|
30
|
+
* Useful when the array might be an {@link IsoBuffer}.
|
|
31
|
+
*
|
|
32
|
+
* @param arr - The array to convert.
|
|
33
|
+
* @param encoding - Optional target encoding; only "utf8" and "base64" are
|
|
34
|
+
* supported, with "utf8" being default.
|
|
35
|
+
* @returns The converted string.
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
function Uint8ArrayToString(arr, encoding) {
|
|
40
|
+
switch (encoding) {
|
|
41
|
+
case "base64": {
|
|
42
|
+
return base64js.fromByteArray(arr);
|
|
43
|
+
}
|
|
44
|
+
case "utf8":
|
|
45
|
+
case "utf-8":
|
|
46
|
+
case undefined: {
|
|
47
|
+
return new TextDecoder().decode(arr);
|
|
48
|
+
}
|
|
49
|
+
default: {
|
|
50
|
+
throw new Error("invalid/unsupported encoding");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.Uint8ArrayToString = Uint8ArrayToString;
|
|
55
|
+
/**
|
|
56
|
+
* Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or
|
|
57
|
+
* {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.
|
|
58
|
+
*
|
|
59
|
+
* @param encoding - The input string's encoding.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
const stringToBuffer = (input, encoding) => IsoBuffer.from(input, encoding).buffer;
|
|
64
|
+
exports.stringToBuffer = stringToBuffer;
|
|
65
|
+
/**
|
|
66
|
+
* Convert binary blob to string format
|
|
67
|
+
*
|
|
68
|
+
* @param blob - the binary blob
|
|
69
|
+
* @param encoding - output string's encoding
|
|
70
|
+
* @returns the blob in string format
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
const bufferToString = (blob, encoding) => IsoBuffer.from(blob).toString(encoding);
|
|
75
|
+
exports.bufferToString = bufferToString;
|
|
76
|
+
/**
|
|
77
|
+
* Determines if an object is an array buffer.
|
|
78
|
+
*
|
|
79
|
+
* @remarks Will detect and reject TypedArrays, like Uint8Array.
|
|
80
|
+
* Reason - they can be viewport into Array, they can be accepted, but caller has to deal with
|
|
81
|
+
* math properly (i.e. Take into account byteOffset at minimum).
|
|
82
|
+
* For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or
|
|
83
|
+
* new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and
|
|
84
|
+
* ignoring byteOffice, length).
|
|
85
|
+
*
|
|
86
|
+
* @param obj - The object to determine if it is an ArrayBuffer.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
function isArrayBuffer(obj) {
|
|
91
|
+
const maybe = obj;
|
|
92
|
+
return (obj instanceof ArrayBuffer ||
|
|
93
|
+
(typeof maybe === "object" &&
|
|
94
|
+
maybe !== null &&
|
|
95
|
+
typeof maybe.byteLength === "number" &&
|
|
96
|
+
typeof maybe.slice === "function" &&
|
|
97
|
+
maybe.byteOffset === undefined &&
|
|
98
|
+
maybe.buffer === undefined));
|
|
99
|
+
}
|
|
100
|
+
exports.isArrayBuffer = isArrayBuffer;
|
|
101
|
+
/**
|
|
102
|
+
* Minimal implementation of Buffer for our usages in the browser environment.
|
|
103
|
+
*
|
|
104
|
+
* @internal
|
|
105
|
+
*/
|
|
106
|
+
class IsoBuffer extends Uint8Array {
|
|
107
|
+
/**
|
|
108
|
+
* Convert the buffer to a string.
|
|
109
|
+
* Only supports encoding the whole string (unlike the Node Buffer equivalent)
|
|
110
|
+
* and only utf8 and base64 encodings.
|
|
111
|
+
*
|
|
112
|
+
* @param encoding - The encoding to use.
|
|
113
|
+
*/
|
|
114
|
+
toString(encoding) {
|
|
115
|
+
return Uint8ArrayToString(this, encoding);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @param value - (string | ArrayBuffer)
|
|
119
|
+
* @param encodingOrOffset - (string | number)
|
|
120
|
+
* @param length - (number)
|
|
121
|
+
*/
|
|
122
|
+
static from(value, encodingOrOffset, length) {
|
|
123
|
+
if (typeof value === "string") {
|
|
124
|
+
return IsoBuffer.fromString(value, encodingOrOffset);
|
|
125
|
+
// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)
|
|
126
|
+
}
|
|
127
|
+
else if (value !== null && typeof value === "object" && isArrayBuffer(value.buffer)) {
|
|
128
|
+
// The version of the from function for the node buffer, which takes a buffer or typed array
|
|
129
|
+
// as first parameter, does not have any offset or length parameters. Those are just silently
|
|
130
|
+
// ignored and not taken into account
|
|
131
|
+
return IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);
|
|
132
|
+
}
|
|
133
|
+
else if (isArrayBuffer(value)) {
|
|
134
|
+
return IsoBuffer.fromArrayBuffer(value, encodingOrOffset, length);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
throw new TypeError();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
static fromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
|
|
141
|
+
const offset = byteOffset ?? 0;
|
|
142
|
+
const validLength = byteLength ?? arrayBuffer.byteLength - offset;
|
|
143
|
+
if (offset < 0 ||
|
|
144
|
+
offset > arrayBuffer.byteLength ||
|
|
145
|
+
validLength < 0 ||
|
|
146
|
+
validLength + offset > arrayBuffer.byteLength) {
|
|
147
|
+
throw new RangeError();
|
|
148
|
+
}
|
|
149
|
+
return new IsoBuffer(arrayBuffer, offset, validLength);
|
|
150
|
+
}
|
|
151
|
+
static fromString(str, encoding) {
|
|
152
|
+
switch (encoding) {
|
|
153
|
+
case "base64": {
|
|
154
|
+
const sanitizedString = this.sanitizeBase64(str);
|
|
155
|
+
const encoded = base64js.toByteArray(sanitizedString);
|
|
156
|
+
return new IsoBuffer(encoded.buffer);
|
|
157
|
+
}
|
|
158
|
+
case "utf8":
|
|
159
|
+
case "utf-8":
|
|
160
|
+
case undefined: {
|
|
161
|
+
const encoded = new TextEncoder().encode(str);
|
|
162
|
+
return new IsoBuffer(encoded.buffer);
|
|
163
|
+
}
|
|
164
|
+
default: {
|
|
165
|
+
throw new Error("invalid/unsupported encoding");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
static isBuffer(obj) {
|
|
170
|
+
throw new Error("unimplemented");
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Sanitize a base64 string to provide to base64-js library.
|
|
174
|
+
* {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'
|
|
175
|
+
* Buffer is.
|
|
176
|
+
*/
|
|
177
|
+
static sanitizeBase64(str) {
|
|
178
|
+
let sanitizedStr = str;
|
|
179
|
+
// Remove everything after padding - Node buffer ignores everything
|
|
180
|
+
// after any padding whereas base64-js does not
|
|
181
|
+
sanitizedStr = sanitizedStr.split("=")[0];
|
|
182
|
+
// Remove invalid characters - Node buffer strips invalid characters
|
|
183
|
+
// whereas base64-js replaces them with "A"
|
|
184
|
+
sanitizedStr = sanitizedStr.replace(/[^\w+-/]/g, "");
|
|
185
|
+
// Check for missing padding - Node buffer tolerates missing padding
|
|
186
|
+
// whereas base64-js does not
|
|
187
|
+
if (sanitizedStr.length % 4 !== 0) {
|
|
188
|
+
const paddingArray = ["", "===", "==", "="];
|
|
189
|
+
sanitizedStr += paddingArray[sanitizedStr.length % 4];
|
|
190
|
+
}
|
|
191
|
+
return sanitizedStr;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
exports.IsoBuffer = IsoBuffer;
|
|
195
|
+
//# sourceMappingURL=bufferBrowser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferBrowser.js","sourceRoot":"","sources":["../src/bufferBrowser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAAsC;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,IAAI,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;SACtD;QACD,OAAO,YAAY,CAAC;IACrB,CAAC;CACD;AAlGD,8BAkGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as base64js from \"base64-js\";\n\n/**\n * Converts a Uint8Array to a string of the provided encoding\n * Useful when the array might be an {@link IsoBuffer}.\n *\n * @param arr - The array to convert.\n * @param encoding - Optional target encoding; only \"utf8\" and \"base64\" are\n * supported, with \"utf8\" being default.\n * @returns The converted string.\n *\n * @internal\n */\nexport function Uint8ArrayToString(arr: Uint8Array, encoding?: string): string {\n\tswitch (encoding) {\n\t\tcase \"base64\": {\n\t\t\treturn base64js.fromByteArray(arr);\n\t\t}\n\t\tcase \"utf8\":\n\t\tcase \"utf-8\":\n\t\tcase undefined: {\n\t\t\treturn new TextDecoder().decode(arr);\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t}\n\t}\n}\n\n/**\n * Converts a {@link https://en.wikipedia.org/wiki/Base64 | base64} or\n * {@link https://en.wikipedia.org/wiki/UTF-8 | utf-8} string to array buffer.\n *\n * @param encoding - The input string's encoding.\n *\n * @internal\n */\nexport const stringToBuffer = (input: string, encoding: string): ArrayBufferLike =>\n\tIsoBuffer.from(input, encoding).buffer;\n\n/**\n * Convert binary blob to string format\n *\n * @param blob - the binary blob\n * @param encoding - output string's encoding\n * @returns the blob in string format\n *\n * @internal\n */\nexport const bufferToString = (blob: ArrayBufferLike, encoding: string): string =>\n\tIsoBuffer.from(blob).toString(encoding);\n\n/**\n * Determines if an object is an array buffer.\n *\n * @remarks Will detect and reject TypedArrays, like Uint8Array.\n * Reason - they can be viewport into Array, they can be accepted, but caller has to deal with\n * math properly (i.e. Take into account byteOffset at minimum).\n * For example, construction of new TypedArray can be in the form of new TypedArray(typedArray) or\n * new TypedArray(buffer, byteOffset, length), but passing TypedArray will result in fist path (and\n * ignoring byteOffice, length).\n *\n * @param obj - The object to determine if it is an ArrayBuffer.\n *\n * @internal\n */\nexport function isArrayBuffer(obj: any): obj is ArrayBuffer {\n\tconst maybe = obj as (Partial<ArrayBuffer> & Partial<Uint8Array>) | undefined;\n\treturn (\n\t\tobj instanceof ArrayBuffer ||\n\t\t(typeof maybe === \"object\" &&\n\t\t\tmaybe !== null &&\n\t\t\ttypeof maybe.byteLength === \"number\" &&\n\t\t\ttypeof maybe.slice === \"function\" &&\n\t\t\tmaybe.byteOffset === undefined &&\n\t\t\tmaybe.buffer === undefined)\n\t);\n}\n\n/**\n * Minimal implementation of Buffer for our usages in the browser environment.\n *\n * @internal\n */\nexport class IsoBuffer extends Uint8Array {\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\tpublic toString(encoding?: string): string {\n\t\treturn Uint8ArrayToString(this, encoding);\n\t}\n\n\t/**\n\t * @param value - (string | ArrayBuffer)\n\t * @param encodingOrOffset - (string | number)\n\t * @param length - (number)\n\t */\n\tstatic from(value, encodingOrOffset?, length?): IsoBuffer {\n\t\tif (typeof value === \"string\") {\n\t\t\treturn IsoBuffer.fromString(value, encodingOrOffset as string | undefined);\n\t\t\t// Capture any typed arrays, including Uint8Array (and thus - IsoBuffer!)\n\t\t} else if (value !== null && typeof value === \"object\" && isArrayBuffer(value.buffer)) {\n\t\t\t// The version of the from function for the node buffer, which takes a buffer or typed array\n\t\t\t// as first parameter, does not have any offset or length parameters. Those are just silently\n\t\t\t// ignored and not taken into account\n\t\t\treturn IsoBuffer.fromArrayBuffer(value.buffer, value.byteOffset, value.byteLength);\n\t\t} else if (isArrayBuffer(value)) {\n\t\t\treturn IsoBuffer.fromArrayBuffer(value, encodingOrOffset as number | undefined, length);\n\t\t} else {\n\t\t\tthrow new TypeError();\n\t\t}\n\t}\n\n\tstatic fromArrayBuffer(\n\t\tarrayBuffer: ArrayBuffer,\n\t\tbyteOffset?: number,\n\t\tbyteLength?: number,\n\t): IsoBuffer {\n\t\tconst offset = byteOffset ?? 0;\n\t\tconst validLength = byteLength ?? arrayBuffer.byteLength - offset;\n\t\tif (\n\t\t\toffset < 0 ||\n\t\t\toffset > arrayBuffer.byteLength ||\n\t\t\tvalidLength < 0 ||\n\t\t\tvalidLength + offset > arrayBuffer.byteLength\n\t\t) {\n\t\t\tthrow new RangeError();\n\t\t}\n\n\t\treturn new IsoBuffer(arrayBuffer, offset, validLength);\n\t}\n\n\tstatic fromString(str: string, encoding?: string): IsoBuffer {\n\t\tswitch (encoding) {\n\t\t\tcase \"base64\": {\n\t\t\t\tconst sanitizedString = this.sanitizeBase64(str);\n\t\t\t\tconst encoded = base64js.toByteArray(sanitizedString);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tcase \"utf8\":\n\t\t\tcase \"utf-8\":\n\t\t\tcase undefined: {\n\t\t\t\tconst encoded = new TextEncoder().encode(str);\n\t\t\t\treturn new IsoBuffer(encoded.buffer);\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new Error(\"invalid/unsupported encoding\");\n\t\t\t}\n\t\t}\n\t}\n\n\tstatic isBuffer(obj: any): boolean {\n\t\tthrow new Error(\"unimplemented\");\n\t}\n\n\t/**\n\t * Sanitize a base64 string to provide to base64-js library.\n\t * {@link https://www.npmjs.com/package/base64-js} is not as tolerant of the same malformed base64 as Node'\n\t * Buffer is.\n\t */\n\tprivate static sanitizeBase64(str: string): string {\n\t\tlet sanitizedStr = str;\n\t\t// Remove everything after padding - Node buffer ignores everything\n\t\t// after any padding whereas base64-js does not\n\t\tsanitizedStr = sanitizedStr.split(\"=\")[0];\n\n\t\t// Remove invalid characters - Node buffer strips invalid characters\n\t\t// whereas base64-js replaces them with \"A\"\n\t\tsanitizedStr = sanitizedStr.replace(/[^\\w+-/]/g, \"\");\n\n\t\t// Check for missing padding - Node buffer tolerates missing padding\n\t\t// whereas base64-js does not\n\t\tif (sanitizedStr.length % 4 !== 0) {\n\t\t\tconst paddingArray = [\"\", \"===\", \"==\", \"=\"];\n\t\t\tsanitizedStr += paddingArray[sanitizedStr.length % 4];\n\t\t}\n\t\treturn sanitizedStr;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Declare the subset of Buffer functionality we want to make available instead of
|
|
7
|
+
* exposing the entirely of Node's typings. This should match the public interface
|
|
8
|
+
* of the browser implementation, so any changes made in one should be made in both.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare class Buffer extends Uint8Array {
|
|
13
|
+
toString(encoding?: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* @param value - (string | ArrayBuffer).
|
|
16
|
+
* @param encodingOrOffset - (string | number).
|
|
17
|
+
* @param length - (number).
|
|
18
|
+
*/
|
|
19
|
+
static from(value: any, encodingOrOffset?: any, length?: any): IsoBuffer;
|
|
20
|
+
static isBuffer(obj: any): obj is Buffer;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare const IsoBuffer: typeof Buffer;
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare type IsoBuffer = Buffer;
|
|
30
|
+
/**
|
|
31
|
+
* Converts a Uint8Array to a string of the provided encoding.
|
|
32
|
+
* @remarks Useful when the array might be an IsoBuffer.
|
|
33
|
+
* @param arr - The array to convert.
|
|
34
|
+
* @param encoding - Optional target encoding; only "utf8" and "base64" are
|
|
35
|
+
* supported, with "utf8" being default.
|
|
36
|
+
* @returns The converted string.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export declare function Uint8ArrayToString(arr: Uint8Array, encoding?: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Convert base64 or utf8 string to array buffer.
|
|
43
|
+
* @param encoding - The input string's encoding.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export declare function stringToBuffer(input: string, encoding: string): ArrayBufferLike;
|
|
48
|
+
/**
|
|
49
|
+
* Convert binary blob to string format
|
|
50
|
+
*
|
|
51
|
+
* @param blob - The binary blob
|
|
52
|
+
* @param encoding - Output string's encoding
|
|
53
|
+
* @returns The blob in string format
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export declare const bufferToString: (blob: ArrayBufferLike, encoding: string) => string;
|
|
58
|
+
//# sourceMappingURL=bufferNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferNode.d.ts","sourceRoot":"","sources":["../src/bufferNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,UAAU;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IACnC;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,KAAA,EAAE,gBAAgB,CAAC,KAAA,EAAE,MAAM,CAAC,KAAA,GAAG,SAAS;IACzD,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM;CACxC;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,eAAS,CAAC;AAEhC;;GAEG;AACH,oBAAY,SAAS,GAAG,MAAM,CAAC;AAE/B;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAG7E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAQ/E;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,SAAU,eAAe,YAAY,MAAM,KAAG,MACjC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.bufferToString = exports.stringToBuffer = exports.Uint8ArrayToString = exports.IsoBuffer = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
exports.IsoBuffer = Buffer;
|
|
12
|
+
/**
|
|
13
|
+
* Converts a Uint8Array to a string of the provided encoding.
|
|
14
|
+
* @remarks Useful when the array might be an IsoBuffer.
|
|
15
|
+
* @param arr - The array to convert.
|
|
16
|
+
* @param encoding - Optional target encoding; only "utf8" and "base64" are
|
|
17
|
+
* supported, with "utf8" being default.
|
|
18
|
+
* @returns The converted string.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
function Uint8ArrayToString(arr, encoding) {
|
|
23
|
+
// Make this check because Buffer.from(arr) will always do a buffer copy
|
|
24
|
+
return Buffer.isBuffer(arr) ? arr.toString(encoding) : Buffer.from(arr).toString(encoding);
|
|
25
|
+
}
|
|
26
|
+
exports.Uint8ArrayToString = Uint8ArrayToString;
|
|
27
|
+
/**
|
|
28
|
+
* Convert base64 or utf8 string to array buffer.
|
|
29
|
+
* @param encoding - The input string's encoding.
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
function stringToBuffer(input, encoding) {
|
|
34
|
+
const iso = exports.IsoBuffer.from(input, encoding);
|
|
35
|
+
// In a Node environment, IsoBuffer may be a Node.js Buffer. Node.js will
|
|
36
|
+
// pool multiple small Buffer instances into a single ArrayBuffer, in which
|
|
37
|
+
// case we need to slice the appropriate span of bytes.
|
|
38
|
+
return iso.byteLength === iso.buffer.byteLength
|
|
39
|
+
? iso.buffer
|
|
40
|
+
: iso.buffer.slice(iso.byteOffset, iso.byteOffset + iso.byteLength);
|
|
41
|
+
}
|
|
42
|
+
exports.stringToBuffer = stringToBuffer;
|
|
43
|
+
/**
|
|
44
|
+
* Convert binary blob to string format
|
|
45
|
+
*
|
|
46
|
+
* @param blob - The binary blob
|
|
47
|
+
* @param encoding - Output string's encoding
|
|
48
|
+
* @returns The blob in string format
|
|
49
|
+
*
|
|
50
|
+
* @internal
|
|
51
|
+
*/
|
|
52
|
+
const bufferToString = (blob, encoding) => exports.IsoBuffer.from(blob).toString(encoding);
|
|
53
|
+
exports.bufferToString = bufferToString;
|
|
54
|
+
//# sourceMappingURL=bufferNode.js.map
|