A stream that emits multiple other streams one after another.

{\bfseries{NB}} Currently {\ttfamily combined-\/stream} works with streams version 1 only. There is ongoing effort to switch this library to streams version 2. Any help is welcome. \+:) Meanwhile you can explore other libraries that provide streams2 support with more or less compatibility with {\ttfamily combined-\/stream}.


\begin{DoxyItemize}
\item \href{https://www.npmjs.com/package/combined-stream2}{\texttt{ combined-\/stream2}}\+: A drop-\/in streams2-\/compatible replacement for the combined-\/stream module.
\item \href{https://www.npmjs.com/package/multistream}{\texttt{ multistream}}\+: A stream that emits multiple other streams one after another.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5841}{}\doxysection{Installation}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5841}

\begin{DoxyCode}{0}
\DoxyCodeLine{npm install combined-\/stream }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5842}{}\doxysection{Usage}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5842}
Here is a simple example that shows how you can use combined-\/stream to combine two files into one\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var CombinedStream = require('combined-\/stream');}
\DoxyCodeLine{var fs = require('fs');}
\DoxyCodeLine{}
\DoxyCodeLine{var combinedStream = CombinedStream.create();}
\DoxyCodeLine{combinedStream.append(fs.createReadStream('file1.txt'));}
\DoxyCodeLine{combinedStream.append(fs.createReadStream('file2.txt'));}
\DoxyCodeLine{}
\DoxyCodeLine{combinedStream.pipe(fs.createWriteStream('combined.txt')); }

\end{DoxyCode}


While the example above works great, it will pause all source streams until they are needed. If you don\textquotesingle{}t want that to happen, you can set {\ttfamily pause\+Streams} to {\ttfamily false}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var CombinedStream = require('combined-\/stream');}
\DoxyCodeLine{var fs = require('fs');}
\DoxyCodeLine{}
\DoxyCodeLine{var combinedStream = CombinedStream.create(\{pauseStreams: false\});}
\DoxyCodeLine{combinedStream.append(fs.createReadStream('file1.txt'));}
\DoxyCodeLine{combinedStream.append(fs.createReadStream('file2.txt'));}
\DoxyCodeLine{}
\DoxyCodeLine{combinedStream.pipe(fs.createWriteStream('combined.txt')); }

\end{DoxyCode}


However, what if you don\textquotesingle{}t have all the source streams yet, or you don\textquotesingle{}t want to allocate the resources (file descriptors, memory, etc.) for them right away? Well, in that case you can simply provide a callback that supplies the stream by calling a {\ttfamily next()} function\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var CombinedStream = require('combined-\/stream');}
\DoxyCodeLine{var fs = require('fs');}
\DoxyCodeLine{}
\DoxyCodeLine{var combinedStream = CombinedStream.create();}
\DoxyCodeLine{combinedStream.append(function(next) \{}
\DoxyCodeLine{  next(fs.createReadStream('file1.txt'));}
\DoxyCodeLine{\});}
\DoxyCodeLine{combinedStream.append(function(next) \{}
\DoxyCodeLine{  next(fs.createReadStream('file2.txt'));}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{combinedStream.pipe(fs.createWriteStream('combined.txt')); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5843}{}\doxysection{API}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5843}
\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5844}{}\doxysubsection{Combined\+Stream.\+create(\mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5844}
Returns a new combined stream object. Available options are\+:


\begin{DoxyItemize}
\item {\ttfamily max\+Data\+Size}
\item {\ttfamily pause\+Streams}
\end{DoxyItemize}

The effect of those options is described below.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5845}{}\doxysubsection{combined\+Stream.\+pause\+Streams = $<$tt$>$true$<$/tt$>$}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5845}
Whether to apply back pressure to the underlaying streams. If set to {\ttfamily false}, the underlaying streams will never be paused. If set to {\ttfamily true}, the underlaying streams will be paused right after being appended, as well as when {\ttfamily delayed\+Stream.\+pipe()} wants to throttle.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5846}{}\doxysubsection{combined\+Stream.\+max\+Data\+Size = $<$tt$>$2 $\ast$ 1024 $\ast$ 1024$<$/tt$>$}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5846}
The maximum amount of bytes (or characters) to buffer for all source streams. If this value is exceeded, {\ttfamily combined\+Stream} emits an `\textquotesingle{}error'\`{} event.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5847}{}\doxysubsection{combined\+Stream.\+data\+Size = $<$tt$>$0$<$/tt$>$}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5847}
The amount of bytes (or characters) currently buffered by {\ttfamily combined\+Stream}.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5848}{}\doxysubsection{combined\+Stream.\+append(stream)}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5848}
Appends the given {\ttfamily stream} to the combined\+Stream object. If {\ttfamily pause\+Streams} is set to \`{}true, this stream will also be paused right away.

{\ttfamily streams} can also be a function that takes one parameter called {\ttfamily next}. {\ttfamily next} is a function that must be invoked in order to provide the {\ttfamily next} stream, see example above.

Regardless of how the {\ttfamily stream} is appended, combined-\/stream always attaches an `\textquotesingle{}error'\`{} listener to it, so you don\textquotesingle{}t have to do that manually.

Special case\+: {\ttfamily stream} can also be a String or Buffer.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5849}{}\doxysubsection{combined\+Stream.\+write(data)}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5849}
You should not call this, {\ttfamily combined\+Stream} takes care of piping the appended streams into itself for you.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5850}{}\doxysubsection{combined\+Stream.\+resume()}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5850}
Causes {\ttfamily combined\+Stream} to start drain the streams it manages. The function is idempotent, and also emits a `\textquotesingle{}resume'\`{} event each time which usually goes to the stream that is currently being drained.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5851}{}\doxysubsection{combined\+Stream.\+pause();}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5851}
If {\ttfamily combined\+Stream.\+pause\+Streams} is set to {\ttfamily false}, this does nothing. Otherwise a `\textquotesingle{}pause'\`{} event is emitted, this goes to the stream that is currently being drained, so you can use it to apply back pressure.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5852}{}\doxysubsection{combined\+Stream.\+end();}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5852}
Sets {\ttfamily combined\+Stream.\+writable} to false, emits an `\textquotesingle{}end'\`{} event, and removes all streams from the queue.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5853}{}\doxysubsection{combined\+Stream.\+destroy();}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5853}
Same as {\ttfamily combined\+Stream.\+end()}, except it emits a `\textquotesingle{}close'{\ttfamily event instead of }\textquotesingle{}end\textquotesingle{}\`{}.\hypertarget{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5854}{}\doxysection{License}\label{md_sfcode_node_modules_combined_stream_Readme_autotoc_md5854}
combined-\/stream is licensed under the MIT license. 