A node module that calls a callback when a readable/writable/duplex stream has completed or failed. \begin{DoxyVerb}npm install end-of-stream
\end{DoxyVerb}
 \href{https://travis-ci.org/mafintosh/end-of-stream}{\texttt{ }}\hypertarget{md_sfcode_node_modules_end_of_stream_README_autotoc_md8407}{}\doxysection{Usage}\label{md_sfcode_node_modules_end_of_stream_README_autotoc_md8407}
Simply pass a stream and a callback to the {\ttfamily eos}. Both legacy streams, streams2 and stream3 are supported.


\begin{DoxyCode}{0}
\DoxyCodeLine{var eos = require('end-\/of-\/stream');}
\DoxyCodeLine{}
\DoxyCodeLine{eos(readableStream, function(err) \{}
\DoxyCodeLine{  // this will be set to the stream instance}
\DoxyCodeLine{    if (err) return console.log('stream had an error or closed early');}
\DoxyCodeLine{    console.log('stream has ended', this === readableStream);}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{eos(writableStream, function(err) \{}
\DoxyCodeLine{    if (err) return console.log('stream had an error or closed early');}
\DoxyCodeLine{    console.log('stream has finished', this === writableStream);}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{eos(duplexStream, function(err) \{}
\DoxyCodeLine{    if (err) return console.log('stream had an error or closed early');}
\DoxyCodeLine{    console.log('stream has ended and finished', this === duplexStream);}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{eos(duplexStream, \{readable:false\}, function(err) \{}
\DoxyCodeLine{    if (err) return console.log('stream had an error or closed early');}
\DoxyCodeLine{    console.log('stream has finished but might still be readable');}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{eos(duplexStream, \{writable:false\}, function(err) \{}
\DoxyCodeLine{    if (err) return console.log('stream had an error or closed early');}
\DoxyCodeLine{    console.log('stream has ended but might still be writable');}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{eos(readableStream, \{error:false\}, function(err) \{}
\DoxyCodeLine{    // do not treat emit('error', err) as a end-\/of-\/stream}
\DoxyCodeLine{\}); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_end_of_stream_README_autotoc_md8408}{}\doxysection{License}\label{md_sfcode_node_modules_end_of_stream_README_autotoc_md8408}
MIT\hypertarget{md_sfcode_node_modules_end_of_stream_README_autotoc_md8409}{}\doxysection{Related}\label{md_sfcode_node_modules_end_of_stream_README_autotoc_md8409}
{\ttfamily end-\/of-\/stream} is part of the \href{https://github.com/maxogden/mississippi}{\texttt{ mississippi stream utility collection}} which includes more useful stream modules similar to this one. 