-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Conversation
@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? |
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. |
@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 |
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. |
nfroidure I think with fs streams you can start over by calling |
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. |
@contra How about this PR, should I clone stream or set an option for this. |
@popomore It should clone the stream via dereferencing (what this PR does). Just pipe to an empty passthrough stream and return the passthrough stream |
I'll merge a PR for this on the current codebase. @popomore or @nfroidure whoever wants to submit one |
I'll rebase this PR for you 😄 |
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