a collection of useful stream utility modules. learn how the modules work using this and then pick the ones you want and use them individually

the goal of the modules included in mississippi is to make working with streams easy without sacrificing speed, error handling or composability.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17666}{}\doxysection{usage}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17666}

\begin{DoxyCode}{0}
\DoxyCodeLine{var miss = require('mississippi') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17667}{}\doxysection{methods}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17667}

\begin{DoxyItemize}
\item \href{\#pipe}{\texttt{ pipe}}
\item \href{\#each}{\texttt{ each}}
\item \href{\#pipeline}{\texttt{ pipeline}}
\item \href{\#duplex}{\texttt{ duplex}}
\item \href{\#through}{\texttt{ through}}
\item \href{\#from}{\texttt{ from}}
\item \href{\#to}{\texttt{ to}}
\item \href{\#concat}{\texttt{ concat}}
\item \href{\#finished}{\texttt{ finished}}
\item \href{\#parallel}{\texttt{ parallel}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17668}{}\doxysubsection{pipe}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17668}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17669}{}\doxyparagraph{$<$tt$>$miss.\+pipe(stream1, stream2, stream3, ..., cb)$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17669}
Pipes streams together and destroys all of them if one of them closes. Calls {\ttfamily cb} with {\ttfamily (error)} if there was an error in any of the streams.

When using standard {\ttfamily source.\+pipe(destination)} the source will {\itshape not} be destroyed if the destination emits close or error. You are also not able to provide a callback to tell when the pipe has finished.

{\ttfamily miss.\+pipe} does these two things for you, ensuring you handle stream errors 100\% of the time (unhandled errors are probably the most common bug in most node streams code)\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17670}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17670}
{\ttfamily miss.\+pipe} is provided by \href{https://www.npmjs.com/package/pump}{\texttt{ `require(\textquotesingle{}pump')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17671}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17671}

\begin{DoxyCode}{0}
\DoxyCodeLine{// lets do a simple file copy}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{}
\DoxyCodeLine{var read = fs.createReadStream('./original.zip')}
\DoxyCodeLine{var write = fs.createWriteStream('./copy.zip')}
\DoxyCodeLine{}
\DoxyCodeLine{// use miss.pipe instead of read.pipe(write)}
\DoxyCodeLine{miss.pipe(read, write, function (err) \{}
\DoxyCodeLine{  if (err) return console.error('Copy error!', err)}
\DoxyCodeLine{  console.log('Copied successfully')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17672}{}\doxysubsection{each}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17672}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17673}{}\doxyparagraph{$<$tt$>$miss.\+each(stream, each, \mbox{[}done\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17673}
Iterate the data in {\ttfamily stream} one chunk at a time. Your {\ttfamily each} function will be called with {\ttfamily (data, next)} where data is a data chunk and next is a callback. Call {\ttfamily next} when you are ready to consume the next chunk.

Optionally you can call {\ttfamily next} with an error to destroy the stream. You can also pass the optional third argument, {\ttfamily done}, which is a function that will be called with {\ttfamily (err)} when the stream ends. The {\ttfamily err} argument will be populated with an error if the stream emitted an error.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17674}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17674}
{\ttfamily miss.\+each} is provided by \href{https://www.npmjs.com/package/stream-each}{\texttt{ `require(\textquotesingle{}stream-\/each')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17675}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17675}

\begin{DoxyCode}{0}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{var split = require('split2')}
\DoxyCodeLine{}
\DoxyCodeLine{var newLineSeparatedNumbers = fs.createReadStream('numbers.txt')}
\DoxyCodeLine{}
\DoxyCodeLine{var pipeline = miss.pipeline(newLineSeparatedNumbers, split())}
\DoxyCodeLine{miss.each(pipeline, eachLine, done)}
\DoxyCodeLine{var sum = 0}
\DoxyCodeLine{}
\DoxyCodeLine{function eachLine (line, next) \{}
\DoxyCodeLine{  sum += parseInt(line.toString())}
\DoxyCodeLine{  next()}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{function done (err) \{}
\DoxyCodeLine{  if (err) throw err}
\DoxyCodeLine{  console.log('sum is', sum)}
\DoxyCodeLine{\} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17676}{}\doxysubsection{pipeline}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17676}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17677}{}\doxyparagraph{$<$tt$>$var pipeline = miss.\+pipeline(stream1, stream2, stream3, ...)$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17677}
Builds a pipeline from all the transform streams passed in as arguments by piping them together and returning a single stream object that lets you write to the first stream and read from the last stream.

If you are pumping object streams together use {\ttfamily pipeline = miss.\+pipeline.\+obj(s1, s2, ...)}.

If any of the streams in the pipeline emits an error or gets destroyed, or you destroy the stream it returns, all of the streams will be destroyed and cleaned up for you.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17678}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17678}
{\ttfamily miss.\+pipeline} is provided by \href{https://www.npmjs.com/package/pumpify}{\texttt{ `require(\textquotesingle{}pumpify')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17679}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17679}

\begin{DoxyCode}{0}
\DoxyCodeLine{// first create some transform streams (note: these two modules are fictional)}
\DoxyCodeLine{var imageResize = require('image-\/resizer-\/stream')(\{width: 400\})}
\DoxyCodeLine{var pngOptimizer = require('png-\/optimizer-\/stream')(\{quality: 60\})}
\DoxyCodeLine{}
\DoxyCodeLine{// instead of doing a.pipe(b), use pipelin}
\DoxyCodeLine{var resizeAndOptimize = miss.pipeline(imageResize, pngOptimizer)}
\DoxyCodeLine{// `resizeAndOptimize` is a transform stream. when you write to it, it writes}
\DoxyCodeLine{// to `imageResize`. when you read from it, it reads from `pngOptimizer`.}
\DoxyCodeLine{// it handles piping all the streams together for you}
\DoxyCodeLine{}
\DoxyCodeLine{// use it like any other transform stream}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{}
\DoxyCodeLine{var read = fs.createReadStream('./image.png')}
\DoxyCodeLine{var write = fs.createWriteStream('./resized-\/and-\/optimized.png')}
\DoxyCodeLine{}
\DoxyCodeLine{miss.pipe(read, resizeAndOptimize, write, function (err) \{}
\DoxyCodeLine{  if (err) return console.error('Image processing error!', err)}
\DoxyCodeLine{  console.log('Image processed successfully')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17680}{}\doxysubsection{duplex}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17680}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17681}{}\doxyparagraph{$<$tt$>$var duplex = miss.\+duplex(\mbox{[}writable, readable, opts\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17681}
Take two separate streams, a writable and a readable, and turn them into a single \href{https://nodejs.org/api/stream.html\#stream_class_stream_duplex}{\texttt{ duplex (readable and writable) stream}}.

The returned stream will emit data from the readable. When you write to it it writes to the writable.

You can either choose to supply the writable and the readable at the time you create the stream, or you can do it later using the {\ttfamily .set\+Writable} and {\ttfamily .set\+Readable} methods and data written to the stream in the meantime will be buffered for you.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17682}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17682}
{\ttfamily miss.\+duplex} is provided by \href{https://www.npmjs.com/package/duplexify}{\texttt{ `require(\textquotesingle{}duplexify')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17683}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17683}

\begin{DoxyCode}{0}
\DoxyCodeLine{// lets spawn a process and take its stdout and stdin and combine them into 1 stream}
\DoxyCodeLine{var child = require('child\_process')}
\DoxyCodeLine{}
\DoxyCodeLine{// @-\/ tells it to read from stdin, -\/-\/data-\/binary sets 'raw' binary mode}
\DoxyCodeLine{var curl = child.spawn('curl -\/X POST -\/-\/data-\/binary @-\/ http://foo.com')}
\DoxyCodeLine{}
\DoxyCodeLine{// duplexCurl will write to stdin and read from stdout}
\DoxyCodeLine{var duplexCurl = miss.duplex(curl.stdin, curl.stdout) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17684}{}\doxysubsection{through}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17684}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17685}{}\doxyparagraph{$<$tt$>$var transformer = miss.\+through(\mbox{[}options, transform\+Function, flush\+Function\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17685}
Make a custom \href{https://nodejs.org/docs/latest/api/stream.html\#stream_class_stream_transform}{\texttt{ transform stream}}.

The {\ttfamily options} object is passed to the internal transform stream and can be used to create an {\ttfamily object\+Mode} stream (or use the shortcut {\ttfamily miss.\+through.\+obj(\mbox{[}...\mbox{]})})

The {\ttfamily transform\+Function} is called when data is available for the writable side and has the signature {\ttfamily (chunk, encoding, cb)}. Within the function, add data to the readable side any number of times with {\ttfamily this.\+push(data)}. Call {\ttfamily cb()} to indicate processing of the {\ttfamily chunk} is complete. Or to easily emit a single error or chunk, call {\ttfamily cb(err, chunk)}

The {\ttfamily flush\+Function}, with signature {\ttfamily (cb)}, is called just before the stream is complete and should be used to wrap up stream processing.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17686}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17686}
{\ttfamily miss.\+through} is provided by \href{https://www.npmjs.com/package/through2}{\texttt{ `require(\textquotesingle{}through2')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17687}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17687}

\begin{DoxyCode}{0}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{}
\DoxyCodeLine{var read = fs.createReadStream('./boring\_lowercase.txt')}
\DoxyCodeLine{var write = fs.createWriteStream('./AWESOMECASE.TXT')}
\DoxyCodeLine{}
\DoxyCodeLine{// Leaving out the options object}
\DoxyCodeLine{var uppercaser = miss.through(}
\DoxyCodeLine{  function (chunk, enc, cb) \{}
\DoxyCodeLine{    cb(null, chunk.toString().toUpperCase())}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  function (cb) \{}
\DoxyCodeLine{    cb(null, 'ONE LAST BIT OF UPPERCASE')}
\DoxyCodeLine{  \}}
\DoxyCodeLine{)}
\DoxyCodeLine{}
\DoxyCodeLine{miss.pipe(read, uppercaser, write, function (err) \{}
\DoxyCodeLine{  if (err) return console.error('Trouble uppercasing!')}
\DoxyCodeLine{  console.log('Splendid uppercasing!')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17688}{}\doxysubsection{from}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17688}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17689}{}\doxyparagraph{$<$tt$>$miss.\+from(\mbox{[}opts\mbox{]}, read)$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17689}
Make a custom \href{https://nodejs.org/docs/latest/api/stream.html\#stream_class_stream_readable}{\texttt{ readable stream}}.

{\ttfamily opts} contains the options to pass on to the Readable\+Stream constructor e.\+g. for creating a readable object stream (or use the shortcut {\ttfamily miss.\+from.\+obj(\mbox{[}...\mbox{]})}).

Returns a readable stream that calls {\ttfamily read(size, next)} when data is requested from the stream.


\begin{DoxyItemize}
\item {\ttfamily size} is the recommended amount of data (in bytes) to retrieve.
\item {\ttfamily next(err, chunk)} should be called when you\textquotesingle{}re ready to emit more data.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17690}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17690}
{\ttfamily miss.\+from} is provided by \href{https://www.npmjs.com/package/from2}{\texttt{ `require(\textquotesingle{}from2')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17691}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17691}

\begin{DoxyCode}{0}
\DoxyCodeLine{function fromString(string) \{}
\DoxyCodeLine{  return miss.from(function(size, next) \{}
\DoxyCodeLine{    // if there's no more content}
\DoxyCodeLine{    // left in the string, close the stream.}
\DoxyCodeLine{    if (string.length <= 0) return next(null, null)}
\DoxyCodeLine{}
\DoxyCodeLine{    // Pull in a new chunk of text,}
\DoxyCodeLine{    // removing it from the string.}
\DoxyCodeLine{    var chunk = string.slice(0, size)}
\DoxyCodeLine{    string = string.slice(size)}
\DoxyCodeLine{}
\DoxyCodeLine{    // Emit "{}chunk"{} from the stream.}
\DoxyCodeLine{    next(null, chunk)}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{// pipe "{}hello world"{} out}
\DoxyCodeLine{// to stdout.}
\DoxyCodeLine{fromString('hello world').pipe(process.stdout) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17692}{}\doxysubsection{to}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17692}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17693}{}\doxyparagraph{$<$tt$>$miss.\+to(\mbox{[}options\mbox{]}, write, \mbox{[}flush\mbox{]})$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17693}
Make a custom \href{https://nodejs.org/docs/latest/api/stream.html\#stream_class_stream_writable}{\texttt{ writable stream}}.

{\ttfamily opts} contains the options to pass on to the Writable\+Stream constructor e.\+g. for creating a writable object stream (or use the shortcut {\ttfamily miss.\+to.\+obj(\mbox{[}...\mbox{]})}).

Returns a writable stream that calls {\ttfamily write(data, enc, cb)} when data is written to the stream.


\begin{DoxyItemize}
\item {\ttfamily data} is the received data to write the destination.
\item {\ttfamily enc} encoding of the piece of data received.
\item {\ttfamily cb(err, data)} should be called when you\textquotesingle{}re ready to write more data, or encountered an error.
\end{DoxyItemize}

{\ttfamily flush(cb)} is called before {\ttfamily finish} is emitted and allows for cleanup steps to occur.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17694}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17694}
{\ttfamily miss.\+to} is provided by \href{https://www.npmjs.com/package/flush-write-stream}{\texttt{ `require(\textquotesingle{}flush-\/write-\/stream')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17695}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17695}

\begin{DoxyCode}{0}
\DoxyCodeLine{var ws = miss.to(write, flush)}
\DoxyCodeLine{}
\DoxyCodeLine{ws.on('finish', function () \{}
\DoxyCodeLine{  console.log('finished')}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{ws.write('hello')}
\DoxyCodeLine{ws.write('world')}
\DoxyCodeLine{ws.end()}
\DoxyCodeLine{}
\DoxyCodeLine{function write (data, enc, cb) \{}
\DoxyCodeLine{  // i am your normal .\_write method}
\DoxyCodeLine{  console.log('writing', data.toString())}
\DoxyCodeLine{  cb()}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{function flush (cb) \{}
\DoxyCodeLine{  // i am called before finish is emitted}
\DoxyCodeLine{  setTimeout(cb, 1000) // wait 1 sec}
\DoxyCodeLine{\} }

\end{DoxyCode}


If you run the above it will produce the following output


\begin{DoxyCode}{0}
\DoxyCodeLine{writing hello}
\DoxyCodeLine{writing world}
\DoxyCodeLine{(nothing happens for 1 sec)}
\DoxyCodeLine{finished }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17696}{}\doxysubsection{concat}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17696}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17697}{}\doxyparagraph{$<$tt$>$var concat = miss.\+concat(cb)$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17697}
Returns a writable stream that concatenates all data written to the stream and calls a callback with the single result.

Calling {\ttfamily miss.\+concat(cb)} returns a writable stream. {\ttfamily cb} is called when the writable stream is finished, e.\+g. when all data is done being written to it. {\ttfamily cb} is called with a single argument, {\ttfamily (data)}, which will contain the result of concatenating all the data written to the stream.

Note that {\ttfamily miss.\+concat} will not handle stream errors for you. To handle errors, use {\ttfamily miss.\+pipe} or handle the {\ttfamily error} event manually.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17698}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17698}
{\ttfamily miss.\+concat} is provided by \href{https://www.npmjs.com/package/concat-stream}{\texttt{ `require(\textquotesingle{}concat-\/stream')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17699}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17699}

\begin{DoxyCode}{0}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{}
\DoxyCodeLine{var readStream = fs.createReadStream('cat.png')}
\DoxyCodeLine{var concatStream = miss.concat(gotPicture)}
\DoxyCodeLine{}
\DoxyCodeLine{function callback (err) \{}
\DoxyCodeLine{  if (err) \{}
\DoxyCodeLine{    console.error(err)}
\DoxyCodeLine{    process.exit(1)}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{miss.pipe(readStream, concatStream, callback)}
\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_mississippi_readme_autotoc_md17700}{}\doxysubsection{finished}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17700}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17701}{}\doxyparagraph{$<$tt$>$miss.\+finished(stream, cb)$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17701}
Waits for {\ttfamily stream} to finish or error and then calls {\ttfamily cb} with {\ttfamily (err)}. {\ttfamily cb} will only be called once. {\ttfamily err} will be null if the stream finished without error, or else it will be populated with the error from the streams {\ttfamily error} event.

This function is useful for simplifying stream handling code as it lets you handle success or error conditions in a single code path. It\textquotesingle{}s used internally {\ttfamily miss.\+pipe}.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17702}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17702}
{\ttfamily miss.\+finished} is provided by \href{https://www.npmjs.com/package/end-of-stream}{\texttt{ `require(\textquotesingle{}end-\/of-\/stream')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17703}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17703}

\begin{DoxyCode}{0}
\DoxyCodeLine{var copySource = fs.createReadStream('./movie.mp4')}
\DoxyCodeLine{var copyDest = fs.createWriteStream('./movie-\/copy.mp4')}
\DoxyCodeLine{}
\DoxyCodeLine{copySource.pipe(copyDest)}
\DoxyCodeLine{}
\DoxyCodeLine{miss.finished(copyDest, function(err) \{}
\DoxyCodeLine{  if (err) return console.log('write failed', err)}
\DoxyCodeLine{  console.log('write success')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17704}{}\doxysubsection{parallel}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17704}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17705}{}\doxyparagraph{$<$tt$>$miss.\+parallel(concurrency, each)$<$/tt$>$}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17705}
This works like {\ttfamily through} except you can process items in parallel, while still preserving the original input order.

This is handy if you wanna take advantage of node\textquotesingle{}s async I/O and process streams of items in batches. With this module you can build your very own streaming parallel job queue.

Note that {\ttfamily miss.\+parallel} preserves input ordering, if you don\textquotesingle{}t need that then you can use \href{https://github.com/almost/through2-concurrent}{\texttt{ through2-\/concurrent}} instead, which is very similar to this otherwise.\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17706}{}\doxysubsubsection{original module}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17706}
{\ttfamily miss.\+parallel} is provided by \href{https://npmjs.org/parallel-transform}{\texttt{ `require(\textquotesingle{}parallel-\/transform')\`{}}}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17707}{}\doxysubsubsection{example}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17707}
This example fetches the GET HTTP headers for a stream of input URLs 5 at a time in parallel.


\begin{DoxyCode}{0}
\DoxyCodeLine{function getResponse (item, cb) \{}
\DoxyCodeLine{  var r = request(item.url)}
\DoxyCodeLine{  r.on('error', function (err) \{}
\DoxyCodeLine{    cb(err)}
\DoxyCodeLine{  \})}
\DoxyCodeLine{  r.on('response', function (re) \{}
\DoxyCodeLine{    cb(null, \{url: item.url, date: new Date(), status: re.statusCode, headers: re.headers\})}
\DoxyCodeLine{    r.abort()}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{miss.pipe(}
\DoxyCodeLine{  fs.createReadStream('./urls.txt'), // one url per line}
\DoxyCodeLine{  split(),}
\DoxyCodeLine{  miss.parallel(5, getResponse),}
\DoxyCodeLine{  miss.through(function (row, enc, next) \{}
\DoxyCodeLine{    console.log(JSON.stringify(row))}
\DoxyCodeLine{    next()}
\DoxyCodeLine{  \})}
\DoxyCodeLine{) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17708}{}\doxysection{see also}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17708}

\begin{DoxyItemize}
\item \href{https://github.com/substack/stream-handbook}{\texttt{ substack/stream-\/handbook}}
\item \href{https://nodejs.org/api/stream.html}{\texttt{ nodejs.\+org/api/stream.html}}
\item \href{https://github.com/thejmazz/awesome-nodejs-streams}{\texttt{ awesome-\/nodejs-\/streams}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_mississippi_readme_autotoc_md17709}{}\doxysection{license}\label{md_sfcode_node_modules_mississippi_readme_autotoc_md17709}
Licensed under the BSD 2-\/clause license. 