-
Notifications
You must be signed in to change notification settings - Fork 108
object API #1
object API #1
Conversation
While I'm at the process of converging the interfaces between js-ipfs and js-ipfs-api, I realised that, although shimming interfaces is easy, shimming return types is not (or pretty much impossible to do right). What I concluded is that one of them has to change in order to match the other. The second thought is that, since I'm at it, we better take the chance and use the newly defined data structs that weren't available before, for example, a What do you think? //++@dignifiedquire & @haad |
I would stay away from using "types" as arguments as well as return types on the dev level. It's already painful enough to do DAGNode is internal to ipfs, but shouldn't be required for devs to wrap their heads around/require in their js file. Does that answer your question? |
@haadcode @dignifiedquire, I've finished setting up the interface for Object. @haadcode as requested, here goes an example for object put and get
This is a straight example, if you check the interface description, it keeps the promise interface and the |
@diasdavid I would suggest to use |
|
||
##### `JavaScript` - ipfs.object.new(layout, [callback]) | ||
|
||
`layout` is the MerkleDAG node type, it can be: `null`, `unixfs-dir`, `unixfs-raw`, `unixfs-file`, `unixfs-metadata`, `unixfs-symlink`. |
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.
I'm guessing all these except for null
are meant to be strings?
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.
exactly
@dignifiedquire sounds good, I like that better as well :) |
What would Can one do Can we have |
Yep :)
It would be able to do:
Similar to the previous, we can support it, but since that the Data field is always a Buffer, it might get confusing for folks, better tell them to use Buffers
That is already there, but with .multihash() instead |
I would really like to see at least |
These would be purely for convenience but would help to keep the current js-ipfs-api return value (object) on par with the js-ipfs.
Otherwise looks good and you're right about the string vs. always buffer as the argument. Let's always require the full |
- Object, with format `{ Data: <data>, Links: [] }` | ||
- Buffer, requiring that the encoding is specified on the encoding | ||
- [DAGNode](https://github.com/vijayee/js-ipfs-merkle-dag/blob/master/src/dag-node.js) | ||
|
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.
I would really like to see at least ipfs.object.put(new Buffer('hey yo'),..) be supported without the {data} wrapper
@dignifiedquire @haadcode the hard part of being able to put a Buffer directly, is the fact that we might indeed to send another serialised format, that go-ipfs, in a Buffer.
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.
sure, but we could make this the default options object: {enc: 'json'}
that way object.put(new Buffer('hello world'))
works and you can always pass a different encoding to change it via the options
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 we default the encoding to JSON when passing the Buffer, then the Buffer should contain something like: new Buffer(JSON.stringify({data: new Buffer('hello world'), links: []))
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.
lets have a call tomorrow about this..
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.
verdict
- no default encoding
- if Buffer is passed with no encoding specified, it is created a DAGNode with that Buffer as Data
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.
So the final version is:
ipfs.object.put(new Buffer('hello'), ...)
ipfs.object.put({ Data: new Buffer('hello') }, ...)
ipfs.object.put(new DAGNode('hello'), ...)
(for the sake of example, fist arg is the data)
Correct?
These all do the same, and return a DAGNode
where node.Data
==> 'hello', correct?
And node.Hash
returns the multihash?
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.
Yes, Yes and no, following the same case as before, new DAGNode(new Buffer('hello'))
node.Data is the data
node.Links are the links
node.multihash() will return the multihash
WIP