-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Backwards compatibility of ipfs.add(urlSource(url))
#3195
Comments
Unsure what would be the generic use case for I agree the best compromise for now is Option 2. |
Not sure what you mean by generic use case, but https://github.com/inkandswitch/xcrpt add-on we did crawl the page to archive it into IPFS. However as I pointed out in the description (quoting below)
That makes
All this to suggest that
|
Changes the return type of this `urlSource` from `AsyncIterable<{ path: string, content: AsyncIterable<Uint8Array> }>` to `{ path: string, content: AsyncIterable<Uint8Array> }` removing one layer of asynchronicity and making return be a single file as opposed to collection of files that always happen to contain one file. fixes: ipfs/js-ipfs#3195 Co-authored-by: achingbrain <alex@achingbrain.net>
This came up in #3081 (comment) and me and @achingbrain agreed to continue discussion on the separate channel (this issue)
Problem
ipfs.add
is supposed to take a single file input (right now it will happily accept many, but that is going to change in the future).ursSource
returns multiple files (see: https://github.com/ipfs/js-ipfs-utils/blob/master/src/files/url-source.js#L5)Options to address this:
ipfs.add
support multiple files.ursSource
return singeFileObject
.Response
object)My personal opinions are as follows
add
/addAll
separation to reduce complexity.urlSource
implementation, there is no reason it for it to returnAsyncIterable<FileObject>
instead it could return{ path: string, * content() { yield * (await new Http().get(url, options)).iterator() } }
.urlSource
is that it will cause buffering in browser because of streaming.{ path: sting, content: AsyncIterable<Blob> }
urlSource
essentially returns an async task (not the result) thatadd
will run and consume resultsadd
is not a scheduler for running tasks, it should take results instead.Response
represents result of fetching remote data.blob
andstream
consumption strategies.await fetch(url)
on user end, but that makes sense (add
isn't a task scheduler).add
should take on a task scheduler role, then it could accept standardRequest
instances.With all that said I think best compromise would be to make
ursSource
returnFileObject
and I can take on that as a followup to #3081 that would enable tests that useurlSource
now.The text was updated successfully, but these errors were encountered: