-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: move from
Buffer
to Uint8Array
- Loading branch information
1 parent
2d3ef20
commit d569eb7
Showing
3 changed files
with
16 additions
and
17 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 |
---|---|---|
@@ -1,8 +1,20 @@ | ||
import { thumbHashToRGBA } from 'thumbhash' | ||
import { base64ToBytes } from './utils' | ||
import { rgbaToDataUri } from './utils/dataUri' | ||
|
||
export function createPngDataUri(hash: string) { | ||
const { w, h, rgba } = thumbHashToRGBA(base64ToBytes(hash)) | ||
const hashArray = base64ToUint8Array(hash) | ||
const { w, h, rgba } = thumbHashToRGBA(hashArray) | ||
|
||
return rgbaToDataUri(w, h, rgba) | ||
} | ||
|
||
function base64ToUint8Array(base64String: string) { | ||
return Uint8Array.from( | ||
globalThis.atob(base64UrlToBase64(base64String)), | ||
x => x.charCodeAt(0), | ||
) | ||
} | ||
|
||
function base64UrlToBase64(base64url: string) { | ||
return base64url.replaceAll('-', '+').replaceAll('_', '/') | ||
} |
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