I'm interested in learning how to retrieve the data wrapped in URL.createObjectURL
.
So, I decided to write the following code snippet.
function convertTypedArrayToURL(typedArray, mimeType) {
return URL.createObjectURL(new Blob([typedArray.buffer], {type: mimeType}))
}
const bytes = Uint8Array.from("https://www.baidu.com/")
// const url = convertTypedArrayToURL(bytes, 'text/html');
const url = convertTypedArrayToURL(bytes, 'text/plain; charset=utf-8');
let blob = await (await fetch(url)).blob();
console.info(new Uint8Array(blob))
let ab = await (await fetch(url)).arrayBuffer();
console.info(new Uint8Array(ab))
The size of the blob or array buffer is 22, which is equal to the length of
"https://www.baidu.com/"
, however, the data within it appears to be all zeros.