Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

All APIs that support Buffer should support Blob #1972

Closed
terichadbourne opened this issue Apr 2, 2019 · 5 comments
Closed

All APIs that support Buffer should support Blob #1972

terichadbourne opened this issue Apr 2, 2019 · 5 comments
Assignees
Labels
exp/novice Someone with a little familiarity can pick up kind/resolved-in-helia P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked

Comments

@terichadbourne
Copy link
Contributor

"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!)

@daviddias
Copy link
Member

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:

  • a)
    • ipfs.add a buffer
    • ipfs.cat returns a buffer
  • b)
    • ipfs.add a blob
    • ipfs.cat returns a buffer

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.

@mikeal
Copy link
Contributor

mikeal commented Apr 3, 2019

@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.

@mikeal
Copy link
Contributor

mikeal commented Apr 3, 2019

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:

  • Learn raw promise API (which we don’t currently teach, we only use async/await).
  • Learn the difference between Blobs and Buffers.
  • Learn the FileReader API and its onload pattern which is quite foreign if you haven’t worked with raw DOM before.

That’s too much. Let’s just accept a Blob ;)

@terichadbourne
Copy link
Contributor Author

I just learned that @hugomrdias already has it in his OKRs to make blobs supported. 🎉 🏆

@alanshaw alanshaw added exp/novice Someone with a little familiarity can pick up P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked labels Apr 11, 2019
@SgtPooki SgtPooki self-assigned this May 17, 2023
@SgtPooki SgtPooki moved this to 🥞 Todo in js-ipfs deprecation May 17, 2023
@SgtPooki
Copy link
Member

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!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/novice Someone with a little familiarity can pick up kind/resolved-in-helia P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked
Projects
No open projects
Status: Done
Development

No branches or pull requests

6 participants