ipfs / js-ipfs-unixfs

JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)
Other
87 stars 34 forks source link

Inconsistent behaviour of isAsyncIterable function between Chrome and Firefox #354

Closed negamaxi closed 1 year ago

negamaxi commented 1 year ago

This code works in Firefox 115.0 and throws error in Chrome 114.0:

const fileObject = Array.from(files).map((file) => ({
  path: file.name,
  content: file.stream(),
}));

for await (const cid of heliaFS.addAll(fileObject)) {
  console.log(cid);
}

The reason is in this function:

https://github.com/ipfs/js-ipfs-unixfs/blob/47218799b4c28b0a4b4dc5a71b9d981e5d803424/packages/ipfs-unixfs-importer/src/dag-builder/index.ts#L37-L39

It returns true in Firefox and false in Chrome for file.stream() result (instance of ReadableStream) passed as value of fileObject.content:

изображение

изображение

achingbrain commented 1 year ago

This is annoying but also expected - please see the browser compatibility table on MDN - https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#browser_compatibility

Only node.js, deno and Firefox support iterating over ReadableStreams as AsyncIterators.

The relevant Chromium bug is here.