Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the clone method #9

Closed
wants to merge 2 commits into from
Closed

Conversation

nfroidure
Copy link
Contributor

Unfortunately, when cloning the file objects, we cannot keep the same stream for them since streams are synchronous when consuming them synchronously.

The added test would fail is there weren't the related changes in index.js

@yocontra
Copy link
Member

@nfroidure Do you think you should be able to file.clone() after the stream has been consumed (partially or completely) and expect a fresh stream?

@nfroidure
Copy link
Contributor Author

I think that when i clone the file here nfroidure@313b02a#diff-e42bc92107d70f0ca365cd690d0406a5R208, no data is consumed yet.

It just consume the streams at different moments nfroidure@313b02a#diff-e42bc92107d70f0ca365cd690d0406a5R221 .

I think that consuming the stream of 2 different files at a different moment will be a common use case and users will expect it to work.

@yocontra
Copy link
Member

@nfroidure But I'm asking - should you be able to consume file.contents multiple times? If you try to consume it and it's already emptied we could start from the beginning

@nfroidure
Copy link
Contributor Author

Do you mean consuming the contents of the stream of a file two times disregarding it's cloned or not? If so, i don't think it isn't possible without buffering it all and i think it is not suitable.

@yocontra
Copy link
Member

nfroidure I think with fs streams you can start over by calling .read(0) on it

@nfroidure
Copy link
Contributor Author

Does it work even if the are multiple pipes? Like that:

fs.createReadStream('file.txt).pipe(stream1).pipe(stream2);
stream2.read(0);

Another problem is that when i consume a stream that just has been cloned, how can i know if the stream is consuming/consumed to be able to choose to replay it or just consume it?

In fact, I cannot figure out how this is related to the issue.

nfroidure added a commit to nfroidure/gulp-svg2ttf that referenced this pull request Jun 28, 2014
nfroidure added a commit to nfroidure/gulp-ttf2eot that referenced this pull request Jun 28, 2014
nfroidure added a commit to nfroidure/gulp-ttf2woff that referenced this pull request Jun 28, 2014
@popomore
Copy link
Contributor

@contra How about this PR, should I clone stream or set an option for this.

@yocontra
Copy link
Member

@popomore It should clone the stream via dereferencing (what this PR does). Just pipe to an empty passthrough stream and return the passthrough stream

@yocontra
Copy link
Member

I'll merge a PR for this on the current codebase. @popomore or @nfroidure whoever wants to submit one

@yocontra yocontra closed this Aug 29, 2014
@popomore
Copy link
Contributor

I'll rebase this PR for you 😄

@popomore popomore mentioned this pull request Aug 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants