Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

New Streaming and Buffered Interfaces #162

Merged
merged 27 commits into from
Nov 17, 2017
Merged

New Streaming and Buffered Interfaces #162

merged 27 commits into from
Nov 17, 2017

Conversation

daviddias
Copy link
Contributor

@daviddias daviddias commented Oct 22, 2017

  • Files
    • Review and declare new function signatures
    • add
      • review spec
      • update tests
      • impl js-ipfs-api
      • impl js-ipfs
    • addReadableStream
      • review spec
      • update tests
      • impl js-ipfs-api
      • impl js-ipfs
    • addPullStream
      • review spec
      • create tests
      • impl js-ipfs-api
      • impl js-ipfs
    • cat
      • review spec
      • update tests
      • impl js-ipfs-api
      • impl js-ipfs
    • catReadableStream
      • review spec
      • create tests
      • impl js-ipfs-api
      • impl js-ipfs
    • catPullStream
      • review spec
      • create tests
      • impl js-ipfs-api
      • impl js-ipfs
    • get
      • review spec
      • update tests
      • impl js-ipfs-api
      • impl js-ipfs
    • getReadableStream
      • review spec
      • create tests
      • impl js-ipfs-api
      • impl js-ipfs
    • getPullStream
      • review spec
      • create tests
      • impl js-ipfs-api
      • impl js-ipfs
    • ls
      • review spec
      • update tests
      • impl js-ipfs-api
      • impl js-ipfs
    • lsReadableStream
      • review spec
      • create tests
      • impl js-ipfs-api
      • impl js-ipfs
    • lsPullStream
      • review spec
      • create tests
      • impl js-ipfs-api
      • impl js-ipfs
    • merge addFromFS to add will do in another PR
    • merge addFromUrl to add will do in another PR

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])
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ups, typo

@daviddias daviddias changed the title WIP New Streaming Interfaces Oct 30, 2017
@daviddias daviddias changed the title New Streaming Interfaces New Streaming and Buffered Interfaces Oct 30, 2017
Copy link

@Beanow Beanow left a 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)
Copy link

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.

Copy link
Contributor Author

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())
Copy link

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())
Copy link

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.

Copy link
Contributor Author

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 = [
]
Copy link
Contributor Author

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.

@daviddias
Copy link
Contributor Author

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

Copy link
Contributor

@dignifiedquire dignifiedquire left a 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)
Copy link
Contributor

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.
Copy link
Contributor

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)
Copy link
Contributor

@pgte pgte Nov 13, 2017

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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?

@mitra42
Copy link

mitra42 commented Nov 16, 2017

Does this fix the bug "c" from #164 which you commented was being worked on here?

@Beanow
Copy link

Beanow commented Nov 16, 2017

Would this be what you're looking for?

https://github.com/ipfs/interface-ipfs-core/blob/dd922523e32ae1d99ed63d1bd18d4e5cb7a20323/SPEC/FILES.md#get

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
  })
})

@daviddias
Copy link
Contributor Author

@mitra42 yes :)

@daviddias daviddias merged commit 8f34b0e into master Nov 17, 2017
@ghost ghost removed the in progress label Nov 17, 2017
@daviddias
Copy link
Contributor Author

@daviddias daviddias deleted the revamp-stream-apis branch November 17, 2017 17:41
@mitra42
Copy link

mitra42 commented Nov 17, 2017

@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.
Qmbzs7jhkBZuVixhnM3J3QhMrL6bcAoSYiRPZrdoX3DhzB single sharded file which works in files.cat
And I also test with a simple json file uploaded with dag.put, which i think would break your files case as it will throw an "invalid node type" error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants