Skip to content

Commit

Permalink
feat(element): support ArrayBufferView (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
idranme authored Jan 15, 2024
1 parent a538f89 commit a06f3cd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/element/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ namespace Element {
// eslint-disable-next-line prefer-const
export let warn: (message: string) => void = () => {}

function createAssetFactory(type: string): Factory<[data: string] | [data: Buffer | ArrayBuffer, type: string]> {
function createAssetFactory(type: string): Factory<[data: string] | [data: Buffer | ArrayBuffer | ArrayBufferView, type: string]> {
return (src, ...args) => {
let prefix = 'base64://'
if (typeof args[0] === 'string') {
Expand All @@ -478,6 +478,8 @@ namespace Element {
src = prefix + src.toString('base64')
} else if (is('ArrayBuffer', src)) {
src = prefix + arrayBufferToBase64(src)
} else if (ArrayBuffer.isView(src)) {
src = prefix + arrayBufferToBase64(src.buffer)
}
if (src.startsWith('base64://')) {
warn(`protocol "base64:" is deprecated and will be removed in the future, please use "data:" instead`)
Expand Down

0 comments on commit a06f3cd

Please sign in to comment.