-
Notifications
You must be signed in to change notification settings - Fork 124
Conversation
I would like the add to be: It'd be also fine to return a If we want to give fine-grained options to define how/what the data is, being able to pass it as @noffle suggested sounds good.
|
- a `Buffer` instance | ||
- a readable stream | ||
|
||
If no value `data` is provided, a Readable stream will be returned, which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Readable/Duplex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops -- I meant Writable. What's the use of this being a Duplex here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to get back the DAGNodes correspondent to the files (and directories) that you are adding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, it's a transform that's happening over the API! Got it. Thanks. :)
Thanks for weighing in, @haadcode! Responses:
We're really keen on having IPFS Core only expose basic operations that all IPFS nodes will be able to support. Adding files from the local filesystem is something that e.g. the browser can't do, so I think it doesn't belong in core. That's not to say however that APIs on top couldn't add this functionality!
Pinging @diasdavid for thoughts on returning first-class objects vs JSON -- I'm not sure what I think yet.
I think we set up a bad expectation here: that CLI should be 1:1 with Core. CLI is a specific interface into the broader world of Core, since CLI has access to things like the local FS, pipes, a shell interpreter, etc. Because of this Core cannot (and shouldn't) match CLI's capabilities. In the case of
How should the API abstract this on the browser, though? Treat file paths as index-db paths? What about future IPFS nodes that have no storage like this at all?
Sure! I'm down for either. :)
Sorry, could you try to explain this again with some more context (maybe an example)? I'm not sure I understand. |
|
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no data
is passed, then, a duplex stream is returned, that pretty much is the duplex stream returned by unixfs-engine Importer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if no data
is passed and no callback
is passed? The possible return matrix starts to get messy -- you'd want a stream and a promise back. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be a misuse of the API.
Note that we need the ability to return a duplex stream to be able to 'add files as they come', through the http-api or through the cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have the callback/promise provide a stream if no data
is passed, but we can't have the function actually return a stream ever, since we went down the road of always returning promises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return the duplex stream on the callback on the interface-ipfs-core. This does not require changes on unixfs-engine. Sounds good?
👍 for making the returned objects be first class DAGNodes :) |
Revisions applied -- just our convo re DAGNodes to resolve. (Aside: I really wish we could simplify this API method: 4 possible input types, 2 types of return values, and both callback and promise control flows.) |
error if the operation was not successful. If no value `data` is provided, `res` | ||
will be a Duplex stream, to which tuples like the above two object formats can | ||
be written and [DAGNode][] objects will be outputted. Otherwise, `res` will be | ||
an array of [DAGNode][]s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give an example please.
stream.write({path: <path to file>, stream: <readable stream>})
// write as many as you want
stream.end()
stream.on('data', function (fileDAGNode) {
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
Good progress :) Let's have tests :) |
be written and [DAGNode][] objects will be outputted. Otherwise, `res` will be | ||
an array of [DAGNode][]s. | ||
|
||
If no `callback` is passed, a promise is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the Promise resolve to? An array of DAGNodes?
We should add examples for the returns
ipfs.files.add(path).then((res) => console.log(res)) // --> [DAGNode1, DAGNode2, ...] ???
Good progress! My thoughts atm:
|
The result from the discussion we had (although I see not document) is that there will be, inside js-ipfs-api, extra API calls like:
These calls will only be available on the js-ipfs-api and are not part of the interface-core-spec
Agree. However, it is fairly easy to distinguish between a call where
Agree and I think this is what it is at the moment, did I miss something? |
Will this be available in Node.js version of js-ipfs? I think it should.
I think the namespacing here is what makes it confusing for me. If we move the add under
Wait, what's your understanding of the value the returned Promise resolves to? A stream or an array?
It's not reflected (yet?) in the PR, perhaps I'm looking at the wrong PR? |
Discussion today:
This sounds really good to me. Separate the stream and Promise control flows and it'll simplify everything nicely. |
Cool! Lots of thinking happened here while I was sleeping. Yes: let's have functions that do one single thing than be a grab bag of inputs and outputs! Here's what I've aggregated from your comments:
I've made these revisions here. @haadcode and @diasdavid re
Here is something it is not:
It's unfortunate, but js-ipfs-api does more things than what "Core IPFS" does, so that overflow needs to go somewhere in its API. So, and niceties that js-ipfs-api provides (like reading files from the FS) needs to be exposed from a higher level API than Core. Maybe this means a new module that builds atop |
Re part 1: Yes that was what we meant Re part 2: I think it's a really good notion of having a module that wraps around both |
path: `test-folder/${name}`, | ||
content: fs.readFileSync(path.join(base, name)) | ||
}) | ||
const dirs = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if there was a test for an empty directory by adding one in data/test-folder/empty
so that it can check this addition to js-ipfs pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Delegating this to #23
for (let i = 0; i < res.length; i++) { | ||
console.log('added', res[i].Hash, res[i].Name) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still use this file?
The tests should cover adding a files:
|
Note for the future: @noffle open branches on the main repos, so that others can collaborate without having to PR your PR in order to make a change :) |
@diasdavid I filed #23 for the tests you mention. I'm going to focus on getting this code in before expanding the test suite. |
I get used to the general github workflow, where you don't tend to have |
All feedback has been addressed!
With this, I can update the dep in my js-ipfs and js-ipfs-api PRs 🎉 |
Awesome work! SO CLOSE :D It feels to me that postponing the tests that will check that this API operates as expect, might be a decision that will quickly backfire. Anything against pushing this tests ahead? All of them are almost created over js-ipfs, js-ipfs-api and js-ipfs-unixfs-engine already, just need to be ported here. |
``` | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add: example:
@diasdavid done: these tests are all now present! All of them except for empty dirs were already present. |
👍 @noffle, rad :D Going to jump into a plane down, wanna squash the commits? |
Also replaces the old javascript test data with Project Gutenberg prose. Also returns object wrapping path+node on ipfs.files.add.
Squashed and ready. |
const testfileBigPath = path.join(__dirname, './data/15mb.random') | ||
testfileBig = fs.createReadStream(testfileBigPath, { bufferSize: 128 }) | ||
} else { | ||
testfile = require('raw!./data/testfile.txt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now use the browserify transform to support fs.readFileSync on the transpilation process as well. We don't need to use the require('raw
@diasdavid This is code I copied out of the existing repos, so these tests never ran in the browser previously either. Agreed 100% that we should make them do so, but given a) what work this PR is blocking, and b) that by not running in them in the browser we're no worse off than we were before (in fact, we're still better off, because there are most tests here than before!), I suggest we merge this now and come back to your those tests later. In fact, I've created a tracking issue for it. SGTM? |
Working on merging this. Made a branch on this repo so that we can all contribute to: #26 , closing this one. |
This is my first draft at merging the wildly different js-ipfs-api and js-ipfs
add
APIs. Notable things:(path, stream)
and(path, content)
are included here. It'd be nice if we could merge them into one style though. Maybe ifcontent
could be a Buffer or Readable?ipfs.files.add()
, but this style is confusing in the way it overloads the API call. I'm on the preference of dropping it but letting folks develop their own utilities for it if they're so inclined. This also gets ambiguous when I don't providedata
orcallback
-- do I get back a Promise OR a Writeable? :Dping @diasdavid @nginnever @dignifiedquire