-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
103 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@smithy/middleware-serde": minor | ||
"@smithy/util-base64": minor | ||
"@smithy/util-utf8": minor | ||
"@smithy/types": minor | ||
--- | ||
|
||
encoders allow string inputs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
import { fromArrayBuffer } from "@smithy/util-buffer-from"; | ||
import { fromUtf8 } from "@smithy/util-utf8"; | ||
|
||
/** | ||
* Converts a Uint8Array of binary data to a base-64 encoded string using | ||
* Converts a Uint8Array of binary data or a utf-8 string to a base-64 encoded string using | ||
* Node.JS's `buffer` module. | ||
* | ||
* @param input The binary data to encode | ||
* @param _input - the binary data or string to encode. | ||
* @returns base64 string. | ||
*/ | ||
export const toBase64 = (input: Uint8Array): string => | ||
fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("base64"); | ||
export const toBase64 = (_input: Uint8Array | string): string => { | ||
let input: Uint8Array; | ||
if (typeof _input === "string") { | ||
input = fromUtf8(_input); | ||
} else { | ||
input = _input as Uint8Array; | ||
} | ||
return fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("base64"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
export const toUtf8 = (input: Uint8Array): string => new TextDecoder("utf-8").decode(input); | ||
export const toUtf8 = (input: Uint8Array | string): string => { | ||
if (typeof input === "string") { | ||
return input; | ||
} | ||
return new TextDecoder("utf-8").decode(input); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import { fromArrayBuffer } from "@smithy/util-buffer-from"; | ||
|
||
export const toUtf8 = (input: Uint8Array): string => | ||
fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("utf8"); | ||
export const toUtf8 = (input: Uint8Array | string): string => { | ||
if (typeof input === "string") { | ||
return input; | ||
} | ||
return fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("utf8"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters