-
Notifications
You must be signed in to change notification settings - Fork 1.2k
All APIs that support Buffer should support Blob #1972
Comments
The tricky thing (that I see) is how to set the user expectation correctly as we won't be able to return the data as a blob if added as a blob, for example:
The reason why b) can be ipfs.cat returns a blob is because IPFS doesn't have any information on how a user expects to receive the data for its app. |
@daviddias this is already the case with the mfs APIs that support Blob instances. Teaching people that we always return a buffer is significantly easier than teaching people how to convert a Blob/File to a buffer. |
For reference, this is roughly what it takes to get a Blob as an ArrayBuffer without external dependencies in way that can be used in async/await code. const blobToBuffer = blob => new Promise(resolve => {
let arrayBuffer
let fileReader = new FileReader()
fileReader.onload = event => resolve(event.target.result)
fileReader.readAsArrayBuffer(blob)
}) That’s without error handling, cause I don’t actually know offhand how FileReader errors work. So, this makes the bar to using this API in the browser:
That’s too much. Let’s just accept a Blob ;) |
I just learned that @hugomrdias already has it in his OKRs to make blobs supported. 🎉 🏆 |
js-ipfs is being deprecated in favor of Helia. You can learn more about this deprecation and read the migration guide. Please feel to reopen with any comments by 2023-06-02. We will do a final pass on reopened issues afterwards (see #4336). This issue is most likely resolved in Helia, please try it out! |
"All APIs that support Buffer should support Blob" - @mikeal
The MFS APIs support Blob, which is really important for the browser. It will be really hard to build ProtoSchool tutorials about the non-MFS file commands without Blob support. (File objects in the browser are Blob instances, so we don't have to do any special conversion in tutorials as long as Blob is supported.)
(Please enlighten me if I'm just not understanding how to do this!)
The text was updated successfully, but these errors were encountered: