-
Notifications
You must be signed in to change notification settings - Fork 124
API proposal for ipfs.files.add #20
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ interface-ipfs-core API. | |
|
||
![](/img/badge.png) | ||
|
||
# How to use the battery tests | ||
# How to use the battery of tests | ||
|
||
## Node.js | ||
|
||
|
@@ -55,6 +55,97 @@ test.all(common) | |
|
||
A valid (read: that follows this interface) IPFS core implementation, must expose the following API. | ||
|
||
## Files | ||
|
||
### `add` | ||
|
||
> Add files and data to IPFS. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.files.add(data, [callback]) | ||
|
||
Where `data` may be | ||
|
||
- an array of objects, each of the form | ||
```js | ||
{ | ||
path: '/tmp/myfile.txt', | ||
content: (Buffer or Readable stream) | ||
} | ||
``` | ||
- a `Buffer` instance | ||
- a `Readable` stream | ||
|
||
`callback` must follow `function (err, res) {}` signature, where `err` is an | ||
error if the operation was not successful. `res` will be an array of | ||
|
||
```js | ||
{ | ||
path: '/tmp/myfile.txt', | ||
node: DAGNode | ||
} | ||
``` | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add: |
||
Example: | ||
```js | ||
var files = [ | ||
{ | ||
path: '/tmp/myfile.txt', | ||
content: (Buffer or Readable stream) | ||
} | ||
] | ||
ipfs.files.add(files, function (err, files) { | ||
// 'files' will be an array of objects | ||
}) | ||
``` | ||
|
||
|
||
### `createAddStream` | ||
|
||
> Add files and data to IPFS using a transform stream. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.files.createAddStream([callback]) | ||
|
||
Provides a Transform stream, where objects can be written of the forms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Provides a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I spent some time thinking about this, and I'm convinced that it's actually a It's a Transform because the input and the output are directly related: each object written is outputted as an object that's been transformed (/w side effects) through the IPFS API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are more objects emitted than those who are written. E.g
will emit 3 times, one for the file and 2 other for the dirs. I understand your reasoning, but feels weird to call it a Transform, it would be like calling a TCP socket a Transform stream, since we will read mutated output. I think both will work @dignifiedquire @haadcode thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transform streams actually very commonly emit more or fewer elements than they are given: a zlib compress transform will yield fewer or more bytes depending on direction; a binary fsk encoder (https://github.com/noffle/binary-fsk) will accept byte buffer objects but emit way more audio data depending on the sample rate. The key distinction is that in Transform streams, the output is in some way calculated from the input. This is in contrast to a Duplex stream (e.g. TCP), which is much more akin to two people on a telephone exchanging messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A transform is stream is just a specialised version of a duplex stream, so really both are correct. |
||
|
||
```js | ||
{ | ||
path: '/tmp/myfile.txt', | ||
content: (Buffer or Readable stream) | ||
} | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related with having it returning a full DAGNode (#20 (comment)), which from what I read you also agree, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I would like DAGNodes returned, but doesn't it come at a high cost? I.e. Won't doing an extra There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 'high cost' is virtual, because currently it is a given fact that the http-api needs improvements and it is better to provide a richer and consistent interface at a cost of another RTT, feeding back that into the http-api design, that simply cut it off. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revision made. |
||
|
||
`callback` must follow `function (err, stream) {}` signature, where `err` is an | ||
error if the operation was not successful. `stream` will be a Transform stream, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
to which tuples like the above two object formats can be written and [DAGNode][] | ||
objects will be outputted. | ||
|
||
If no `callback` is passed, a promise is returned. | ||
|
||
```js | ||
ipfs.files.createAddStream(function (err, stream) { | ||
stream.on('data', function (file) { | ||
// 'file' will be of the form | ||
// { | ||
// path: '/tmp/myfile.txt', | ||
// node: DAGNode | ||
// } | ||
}) | ||
|
||
stream.write({path: <path to file>, content: <buffer or readable stream>}) | ||
// write as many as you want | ||
|
||
stream.end() | ||
}) | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if no There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. We can have the callback/promise provide a stream if no There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
||
|
||
## Object | ||
|
||
### `object.new` | ||
|
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