forked from video-dev/can-autoplay
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
c7c9ccd
commit 22ac214
Showing
5 changed files
with
184 additions
and
126 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function base64toBlob (base64) { | ||
const base64Regex = /^data:([^;]+);base64,(.+)$/i | ||
const matches = base64.match(base64Regex) | ||
const contentType = matches[1]; | ||
const base64Data = matches[2]; | ||
|
||
const sliceSize = 1024 | ||
const byteCharacters = atob(base64Data) | ||
const bytesLength = byteCharacters.length | ||
const slicesCount = Math.ceil(bytesLength / sliceSize) | ||
const byteArrays = new Array(slicesCount) | ||
|
||
for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) { | ||
const begin = sliceIndex * sliceSize | ||
const end = Math.min(begin + sliceSize, bytesLength) | ||
|
||
const bytes = new Array(end - begin) | ||
for (let offset = begin, i = 0; offset < end; ++i, ++offset) { | ||
bytes[i] = byteCharacters[offset].charCodeAt(0) | ||
} | ||
byteArrays[sliceIndex] = new Uint8Array(bytes) | ||
} | ||
return new Blob(byteArrays, { type: contentType }) | ||
} | ||
|
||
export default base64toBlob |
Oops, something went wrong.