Like {\ttfamily fs.\+create\+Write\+Stream(...)}, but atomic.

Writes to a tmp file and does an atomic {\ttfamily fs.\+rename} to move it into place when it\textquotesingle{}s done.

First rule of debugging\+: {\bfseries{It\textquotesingle{}s always a race condition.}}\hypertarget{md_sfcode_node_modules_fs_write_stream_atomic_README_autotoc_md11071}{}\doxysection{USAGE}\label{md_sfcode_node_modules_fs_write_stream_atomic_README_autotoc_md11071}

\begin{DoxyCode}{0}
\DoxyCodeLine{var fsWriteStreamAtomic = require('fs-\/write-\/stream-\/atomic')}
\DoxyCodeLine{// options are optional.}
\DoxyCodeLine{var write = fsWriteStreamAtomic('output.txt', options)}
\DoxyCodeLine{var read = fs.createReadStream('input.txt')}
\DoxyCodeLine{read.pipe(write)}
\DoxyCodeLine{}
\DoxyCodeLine{// When the write stream emits a 'finish' or 'close' event,}
\DoxyCodeLine{// you can be sure that it is moved into place, and contains}
\DoxyCodeLine{// all the bytes that were written to it, even if something else}
\DoxyCodeLine{// was writing to `output.txt` at the same time. }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_fs_write_stream_atomic_README_autotoc_md11072}{}\doxysubsection{$<$tt$>$fs\+Write\+Stream\+Atomic(filename, \mbox{[}options\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_fs_write_stream_atomic_README_autotoc_md11072}

\begin{DoxyItemize}
\item {\ttfamily filename} \{String\} The file we want to write to
\item {\ttfamily options} \{Object\}
\begin{DoxyItemize}
\item {\ttfamily chown} \{Object\} User and group to set ownership after write
\begin{DoxyItemize}
\item {\ttfamily uid} \{Number\}
\item {\ttfamily gid} \{Number\}
\end{DoxyItemize}
\item {\ttfamily encoding} \{String\} default = \textquotesingle{}utf8\textquotesingle{}
\item {\ttfamily mode} \{Number\} default = {\ttfamily 0666}
\item {\ttfamily flags} \{String\} default = `\textquotesingle{}w'\`{} 
\end{DoxyItemize}
\end{DoxyItemize}