mkdir-and-mv-stream
stream into a directory that doesn't exist yet, and fail safely if the process crashes.
writing npmd, I've found my self doing this a lot:
//make a directory for the file to be in.
It's important to stream to a safe location and then stream the file.
If the program crashes while writing the file, this depends on your program,
but an incomplete file is probably corrupt. fs.rename
(mv
) is atomic,
so the file will appear in the final location if and only if the program did not crash.
License
MIT