-
Notifications
You must be signed in to change notification settings - Fork 124
Conversation
SPEC/FILES.md
Outdated
|
||
> Add files and data to IPFS using a transform stream. | ||
|
||
##### `Go` **WIP** | ||
|
||
##### `JavaScript` - ipfs.files.createAddStream([options], [callback]) | ||
##### `JavaScript` - ipfs.files.AddReadableStream([options], [callback]) |
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.
please don't capitalize method names in JavaScript, that makes for some very surprising apis.
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.
ups, typo
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.
Haven't had a moment to look at the tests yet, but some thoughts on the spec document.
- a [`Buffer instance`][b] | ||
- a [`Readable Stream`][rs] | ||
- a [`Pull Stream`][ps] | ||
- a Path (caveat: will only work in 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.
If we're adding node only path strings, shouldn't we add browser only File instances? https://developer.mozilla.org/en-US/docs/Web/API/File
I think it would allow for great simplification and ample opportunity to do the right thing under the hood.
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.
Sounds good!
SPEC/FILES.md
Outdated
throw err | ||
} | ||
|
||
console.log(file.toString()) |
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.
This toString call is tricky as it assumes utf8 encoding of the binary data. Perhaps a comment about encoding or passing utf8 explicitly would be a good hint.
SPEC/FILES.md
Outdated
console.log(file.path) | ||
file.content.pipe(process.stdout) | ||
console.log(file.path.toString()) |
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.
Logging the path twice?
What about the path and filesize so we touched the content buffer as well.
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.
Thank you for catching that!
@@ -52,142 +57,342 @@ const files = [ | |||
] |
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.
Really tempted to change the name of hash
to cid
.
Spec and js-ipfs-api have been updated!I've finished updating the spec and the implementation in js-ipfs-api. Next step is to implement the same interface in js-ipfs. Please review as soon as possible to make sure that nothing gets missed. Overall I'm really happy with the simplicity of the new calls and I bet a lot more people will be able to use both modules without having to go through the learning of Node.js Streams and/or Pull Streams |
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.
Only reviewed the interface, not the code
```JavaScript | ||
const validCID = 'QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF' | ||
|
||
const stream = ipfs.files.getReadableStream(validCID) |
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.
Shouldn't this be ... ipfs.lsReadableStream(..
instead?
SPEC/FILES.md
Outdated
|
||
#### `lsPullStream` | ||
|
||
> Fetch a file or an entire directory tree from IPFS that is addressed by a valid IPFS Path. The files will be yielded as Readable Streams. |
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 Streams/pull stream ?
```JavaScript | ||
const validCID = 'QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF' | ||
|
||
const stream = ipfs.files.getReadableStream(validCID) |
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.
shouldn't this be ipfs.lsPullStream
instead?
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.
thanks for the catch! :)
SPEC/FILES.md
Outdated
```JavaScript | ||
const validCID = 'QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF' | ||
|
||
ipfs.files.ls(validCID, function (err, files) { |
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.
shouldn't this be ipfs.ls
instead?
Does this fix the bug "c" from #164 which you commented was being worked on here? |
Would this be what you're looking for? const validCID = 'QmQ2r6iMNpky5f1m4cnm3Yqw8VSvjuKpTcK1X7dBR1LkJF'
ipfs.files.get(validCID, function (err, files) {
files.forEach((file) => {
console.log(file.path)
console.log(file.content.toString('utf8')) // <-- file.content is a Buffer
})
}) |
@mitra42 yes :) |
dd92252
to
f6aba4a
Compare
@Beanow That case you've given is another case, i.e. where the hash refers to multiple files and having .content available would be a much nicer interface than having to use streams. Does that work if it was a single file. My two tests are with QmTds3bVoiM9pzfNJX6vT2ohxnezKPdaGHLd4Ptc4ACMLa (a file that should be 184324 bytes and therefore not sharded - and failed previous files.cat. |
merge addFromFS to addwill do in another PRmerge addFromUrl to addwill do in another PR