You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
I've been trying to generate a large file, writing one line at a time, and I ran into a serious problem. Here's a test case (original CoffeeScript gisted here:
This will simply write ten million random numbers to a file, separated by newlines. Try running it; it'll take 15+ minutes to complete. Then go to the command line and do
grep -nE ^[0-9][0-9]+ test.txt
This will match several lines starting with more than one decimal digit, which should be impossible (in fact, the code that wrote those lines would have written to the console to alert us, because such a line doesn't match /^(\d\.\d+(e-\d+)?)\n$/). For instance, in one run I got
I've done repeated tests, and this never happens when I do a million writes. It's that jump to 10,000,000 that does it (even though the bad writes can, as you see above, occur well before the millionth one)!
For the record, I'm running Node 0.4.2 under Mac OS 10.6.6, with an SSD. I haven't run this test on any other systems.
The text was updated successfully, but these errors were encountered:
The order of repeated fs.write() calls is not guaranteed. If you want to make sure that the order is constant, then you need to wait for the cb to fire before doing the next write, or use fs.createWriteStream, which buffers writes for you.
The docs do mention inconsistent order as a possibility, but it hadn't occurred to me that this could cause writes to overlap or be truncated (and goodness know how that P got in there).
I've submitted a pull request to note this in the docs: #811
I've been trying to generate a large file, writing one line at a time, and I ran into a serious problem. Here's a test case (original CoffeeScript gisted here:
This will simply write ten million random numbers to a file, separated by newlines. Try running it; it'll take 15+ minutes to complete. Then go to the command line and do
This will match several lines starting with more than one decimal digit, which should be impossible (in fact, the code that wrote those lines would have written to the console to alert us, because such a line doesn't match
/^(\d\.\d+(e-\d+)?)\n$/
). For instance, in one run I got...and so on for about 50 lines.
I've done repeated tests, and this never happens when I do a million writes. It's that jump to 10,000,000 that does it (even though the bad writes can, as you see above, occur well before the millionth one)!
For the record, I'm running Node 0.4.2 under Mac OS 10.6.6, with an SSD. I haven't run this test on any other systems.
The text was updated successfully, but these errors were encountered: