-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
custom WriteStream on writes end of stream #202
Comments
@doowb that's interesting because I copied most of the logic from node's write stream. From my initial digging, I found that fs.write maintains the position internally if you don't pass a position. Can you provide an example repo of this? |
Oh, that might have happened during refactoring (notice the double semi-colon). We can probably get away with hardcoding that as |
That was my first thought too, but will that just "append" to the file if it already has contents? |
@doowb the |
K, that's the part I missed. Passing |
Here's a simple repo showing the issue in case it can be used for a test: https://github.com/doowb/vinyl-fs-write-stream |
Played around with @doowb's repo, and I think's it's doing more than just cutting off beginning of the file. I tested files of different lengths and found this when using a file 1450 lines long.
It looks like script reaches the 1449th line then decides to go back to the top of the file and overwrite the existing content (lines 0 & 1). It seems that the script just runs out of memory and decides to cannibalise existing memory. I created and even larger file, 3550 lines, and passed all of them through index.js.
So the outputted files are all capped at 65536 bytes, or 2 to the 16th. I'm thinking we're running up against some system wide limit here. |
@criticalmash data comes through the stream in chunks (probably 64k) so each chunk is written to the file starting at position 0. If the last chunk is smaller than the max, then the data is written at the beginning of the file and the rest of the data from the previous chunk is kept. I did a PR that changes this to pass in You can try out the changes by doing |
Though 64k was a bit low as a limit. But given that it's streaming chunks of content in 64k packages it now makes sense. Tried your fork, it works as expected. |
When a stream is large enough, only the end is written to the file.
The code here is using
this.pos
which is set tonull
when the append flag is set. This is good forwriteFile
which writes the entire file at once, but it should be different inside theWriteStream
.I've tried just passing in
null
so the contents will be written to the end of the file and also, updating thethis.pos
in theonWrite
callback. I think the latter is a better approach since the append flag may still be used.I think updating the onWrite callback would look like this:
I can submit a PR if you'd like. I'm not sure the best approach for testing this.
Thanks to @criticalmash for discovering this and working with me on debugging.
The text was updated successfully, but these errors were encountered: