-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't try to grow the buffer more than allowed by the system
Closes: image-js/fast-png#42
- Loading branch information
Showing
5 changed files
with
79 additions
and
8 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
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,21 @@ | ||
/** | ||
* Decode a Uint8Array to a string. | ||
* @param bytes - The Uint8Array to decode. | ||
* @param encoding - The encoding to use. Defaults to 'utf8'. | ||
* @returns The decoded string. | ||
*/ | ||
export function decode(bytes: Uint8Array, encoding = 'utf8'): string { | ||
const decoder = new TextDecoder(encoding); | ||
return decoder.decode(bytes); | ||
} | ||
|
||
const encoder = new TextEncoder(); | ||
|
||
/** | ||
* Encode a string as UTF-8 to a Uint8Array. | ||
* @param str - The string to encode. | ||
* @returns The encoded Uint8Array. | ||
*/ | ||
export function encode(str: string): Uint8Array { | ||
return encoder.encode(str); | ||
} |
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