Writable stream that concatenates all the data from a stream and calls a callback with the result. Use this when you want to collect all the data from a stream into a single buffer.

\href{https://travis-ci.org/maxogden/concat-stream}{\texttt{ }}

\href{https://nodei.co/npm/concat-stream/}{\texttt{ }}\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6134}{}\doxysubsection{description}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6134}
Streams emit many buffers. If you want to collect all of the buffers, and when the stream ends concatenate all of the buffers together and receive a single buffer then this is the module for you.

Only use this if you know you can fit all of the output of your stream into a single Buffer (e.\+g. in RAM).

There are also {\ttfamily object\+Mode} streams that emit things other than Buffers, and you can concatenate these too. See below for details.\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6135}{}\doxysection{Related}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6135}
{\ttfamily concat-\/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.\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6136}{}\doxysubsection{examples}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6136}
\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6137}{}\doxysubsubsection{Buffers}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6137}

\begin{DoxyCode}{0}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{var concat = require('concat-\/stream')}
\DoxyCodeLine{}
\DoxyCodeLine{var readStream = fs.createReadStream('cat.png')}
\DoxyCodeLine{var concatStream = concat(gotPicture)}
\DoxyCodeLine{}
\DoxyCodeLine{readStream.on('error', handleError)}
\DoxyCodeLine{readStream.pipe(concatStream)}
\DoxyCodeLine{}
\DoxyCodeLine{function gotPicture(imageBuffer) \{}
\DoxyCodeLine{  // imageBuffer is all of `cat.png` as a node.js Buffer}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{function handleError(err) \{}
\DoxyCodeLine{  // handle your error appropriately here, e.g.:}
\DoxyCodeLine{  console.error(err) // print the error to STDERR}
\DoxyCodeLine{  process.exit(1) // exit program with non-\/zero exit code}
\DoxyCodeLine{\}}

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6138}{}\doxysubsubsection{Arrays}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6138}

\begin{DoxyCode}{0}
\DoxyCodeLine{var write = concat(function(data) \{\})}
\DoxyCodeLine{write.write([1,2,3])}
\DoxyCodeLine{write.write([4,5,6])}
\DoxyCodeLine{write.end()}
\DoxyCodeLine{// data will be [1,2,3,4,5,6] in the above callback }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6139}{}\doxysubsubsection{Uint8\+Arrays}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6139}

\begin{DoxyCode}{0}
\DoxyCodeLine{var write = concat(function(data) \{\})}
\DoxyCodeLine{var a = new Uint8Array(3)}
\DoxyCodeLine{a[0] = 97; a[1] = 98; a[2] = 99}
\DoxyCodeLine{write.write(a)}
\DoxyCodeLine{write.write('!')}
\DoxyCodeLine{write.end(Buffer.from('!!1')) }

\end{DoxyCode}


See {\ttfamily test/} for more examples\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6140}{}\doxysection{methods}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6140}

\begin{DoxyCode}{0}
\DoxyCodeLine{var concat = require('concat-\/stream') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6141}{}\doxysubsection{var writable = concat(opts=\{\}, cb)}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6141}
Return a {\ttfamily writable} stream that will fire {\ttfamily cb(data)} with all of the data that was written to the stream. Data can be written to {\ttfamily writable} as strings, Buffers, arrays of byte integers, and Uint8\+Arrays.

By default {\ttfamily concat-\/stream} will give you back the same data type as the type of the first buffer written to the stream. Use {\ttfamily opts.\+encoding} to set what format {\ttfamily data} should be returned as, e.\+g. if you if you don\textquotesingle{}t want to rely on the built-\/in type checking or for some other reason.


\begin{DoxyItemize}
\item {\ttfamily string} -\/ get a string
\item {\ttfamily buffer} -\/ get back a Buffer
\item {\ttfamily array} -\/ get an array of byte integers
\item {\ttfamily uint8array}, {\ttfamily u8}, {\ttfamily uint8} -\/ get back a Uint8\+Array
\item {\ttfamily object}, get back an array of Objects
\end{DoxyItemize}

If you don\textquotesingle{}t specify an encoding, and the types can\textquotesingle{}t be inferred (e.\+g. you write things that aren\textquotesingle{}t in the list above), it will try to convert concat them into a {\ttfamily Buffer}.

If nothing is written to {\ttfamily writable} then {\ttfamily data} will be an empty array {\ttfamily \mbox{[}\mbox{]}}.\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6142}{}\doxysection{error handling}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6142}
{\ttfamily concat-\/stream} does not handle errors for you, so you must handle errors on whatever streams you pipe into {\ttfamily concat-\/stream}. This is a general rule when programming with node.\+js streams\+: always handle errors on each and every stream. Since {\ttfamily concat-\/stream} is not itself a stream it does not emit errors.

We recommend using \href{https://npmjs.org/end-of-stream}{\texttt{ {\ttfamily end-\/of-\/stream}}} or \href{https://npmjs.org/pump}{\texttt{ {\ttfamily pump}}} for writing error tolerant stream code.\hypertarget{md_sfcode_node_modules_concat_stream_readme_autotoc_md6143}{}\doxysection{license}\label{md_sfcode_node_modules_concat_stream_readme_autotoc_md6143}
MIT LICENSE 