-
Notifications
You must be signed in to change notification settings - Fork 109
Consider enabling add(path)
to the files API
#118
Comments
👎 on this, it makes the api more complicated. Having an api call that has entirely different semantics depending on if it is run in node.js or the browser seems like it will only cause more confusion. |
This is a basic expectation of ipfs nodes and tooling.
Bottom line, these should be trivially easy to use: // direct analogues with ipfs add in the cli, in node.
ipfs.add("~/path/to/my-file")
ipfs.add("~/path/to/my-dir", {recursive: true})
ipfs.add("my-file")
ipfs.add("my-dir", {recursive: true})
ipfs.add(stream) // makes a file
// direct analogues with ipfs add in the cli, but on the browser
ipfs.add("https://foo.com/my-page")
// arguably, people would expcet this to work like wget mirroring:
ipfs.add("https://foo.com/my-page", {recursive: true})
// but i'm fine not supporting it. Conversely, i would expect cat to work equally easily: ipfs.cat(ipfsPath) # returns a stream The emphasis here is in:
|
"i just want to add some json and get it back" this should be absolutely trivial, and exactly the same as it works in the cli. |
@diasdavid it seems to be already working on the JavaScript API. Is there anything else to do on this issue I can help with? |
The docs in the JavaScript API were erroneous. The files.add method only allows Buffers or Streams (either directly or as the |
There is a very valuable and impressive work being done and thought through by @alanshaw, @olizilla and @achingbrain with regards to APIs around Files and js-ipfs APIs in general (ipfsx). As a stepping stone towards that, I want to bring the .addFromFs to the top level. In the future there will be just on ipfs.add command when we have the async generators goodness (and no more myriad of Streams) |
Adding files by path has been split out into the |
@jbenet brought up that a lot of users will expect
ipfs.add(path)
to just work as if they were in the terminal.In the past, we went through several iterations and discussions and eventually ended up agreeing that it would be beneficial to have utilities like addFromFs and addFromUrl as actions that are explicit, this keeps the promise intact that code can be run in the browser and in Node.js, as long as the dev is using the ipfs-core API.
We can add this feature, we will just need to be verbose about that caveat.
The text was updated successfully, but these errors were encountered: