"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 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鈥檚 without error handling, cause I don鈥檛 actually know offhand how FileReader errors work.
So, this makes the bar to using this API in the browser:
onload pattern which is quite foreign if you haven鈥檛 worked with raw DOM before.That鈥檚 too much. Let鈥檚 just accept a Blob ;)
I just learned that @hugomrdias already has it in his OKRs to make blobs supported. 馃帀 馃弳
Most helpful comment
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.
That鈥檚 without error handling, cause I don鈥檛 actually know offhand how FileReader errors work.
So, this makes the bar to using this API in the browser:
onloadpattern which is quite foreign if you haven鈥檛 worked with raw DOM before.That鈥檚 too much. Let鈥檚 just accept a Blob ;)