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

Set the FileStreamConverter explicitly #701

Merged
merged 2 commits into from
Mar 14, 2018
Merged

Conversation

vmx
Copy link
Contributor

@vmx vmx commented Feb 23, 2018

The SendFilesStream used to run the FileStreamConverter automatically.
With making it an option to use a converter, SendFilesStream can be
used outside of the Files API, e.g. for the DAG API.

@ghost ghost assigned vmx Feb 23, 2018
@ghost ghost added the in progress label Feb 23, 2018
@vmx vmx requested a review from pgte February 23, 2018 20:42
@vmx
Copy link
Contributor Author

vmx commented Feb 23, 2018

@pgte Can you especially review:

  1. If all those places where I set the converter explicitly really need it
  2. I really dislike the code duplication in src/utils/send-files-stream.js. As you're better with streams than I am, I hope you know a nice/cleaner/better way.

Copy link
Contributor

@pgte pgte left a comment

Choose a reason for hiding this comment

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

I suggested a name change, what looks like some redundancy in options argument, and the lack of back-pressure in the result of the send-files-stream.

module.exports = (send) => {
return (options) => {
options = options || {}
options.converter = FileStreamConverter
Copy link
Contributor

Choose a reason for hiding this comment

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

If add-readable-stream already sets the converter, you don't need to set it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't need to, but I could :) In the current way it would make sure that the converter for the PullStream is always the FileStreamConverter no matter which value it had. I think that makes sense, doesn't it?

@@ -1,6 +1,13 @@
'use strict'

const SendFilesStream = require('../utils/send-files-stream')
const FileStreamConverter = require('../utils/file-stream-converter')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think file-stream-converter is still to ambiguous. I would call it file-result-stream-converter.

convertedResponse.on('data', (d) => retStream.push(d))
response.pipe(convertedResponse)
if (options.converter) {
response.on('data', (d) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Because you're not returning the converted response, the back-pressure here doesn't work.
Instead, I suggest that you create a duplex stream from the input stream and the converted response, and that's what you would return. (This way, the client can do back-pressure: if the result data is being processed too slowly and the server implements back-pressure properly, the back-pressure should propagate all the way to the server and back into the request stream).

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps you could use duplexify to create a duplex stream from the writable (the client pushing files) and the readable (the result stream).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this a bug in the original code? I don't see how my code is different from the original one in case a converter is set.

Copy link
Contributor

Choose a reason for hiding this comment

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

@vmx I see, this is a problem that was already there before, I only spotted it now.
Feel free to ignore this (and we should probably open an issue with this one). :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Did the issue get created?

Copy link
Contributor

Choose a reason for hiding this comment

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

Saw it now.

The `SendFilesStream` used to run the `FileResultStreamConverter`
automatically. With making it an option to use a converter,
`SendFilesStream` can be used outside of the Files API, e.g. for
the DAG API.

Closes #696.
@vmx vmx force-pushed the explicit-converter branch from 6d90b46 to 2c47b4f Compare February 26, 2018 14:31
@vmx
Copy link
Contributor Author

vmx commented Feb 26, 2018

@pgte I did a force push with the naming suggestion. I should have addressed everything now.

Could you please open an issue for the back-pressure problem? I can get what the problem is, so you'd be better explaining it.

@pgte
Copy link
Contributor

pgte commented Feb 26, 2018

@vmx opened back-pressure issue here #702

Copy link
Contributor

@pgte pgte left a comment

Choose a reason for hiding this comment

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

LGTM!

@vmx
Copy link
Contributor Author

vmx commented Feb 28, 2018

The tests passed on Node 6 (https://travis-ci.org/ipfs/js-ipfs-api/jobs/346307987#L3540) and 8 (https://travis-ci.org/ipfs/js-ipfs-api/jobs/346307988#L5306) on Travis. @diasdavid Is that good enough for a merge?

@daviddias
Copy link
Contributor

@vmx I liked your proposal to disable browser tests in Travis and Circle meanwhile (just pass on Jenkins). Wanna do that first?

@daviddias daviddias merged commit dfad55e into master Mar 14, 2018
@ghost ghost removed the in progress label Mar 14, 2018
@daviddias daviddias deleted the explicit-converter branch March 14, 2018 14:30
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.

3 participants