pump is a small node module that pipes streams together and destroys all of them if one of them closes.


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install pump }

\end{DoxyCode}


\href{http://travis-ci.org/mafintosh/pump}{\texttt{ }}\hypertarget{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23546}{}\doxysection{What problem does it solve?}\label{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23546}
When using standard {\ttfamily source.\+pipe(dest)} source will {\itshape not} be destroyed if dest emits close or an error. You are also not able to provide a callback to tell when then pipe has finished.

pump does these two things for you\hypertarget{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23547}{}\doxysection{Usage}\label{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23547}
Simply pass the streams you want to pipe together to pump and add an optional callback


\begin{DoxyCode}{0}
\DoxyCodeLine{var pump = require('pump')}
\DoxyCodeLine{var fs = require('fs')}
\DoxyCodeLine{}
\DoxyCodeLine{var source = fs.createReadStream('/dev/random')}
\DoxyCodeLine{var dest = fs.createWriteStream('/dev/null')}
\DoxyCodeLine{}
\DoxyCodeLine{pump(source, dest, function(err) \{}
\DoxyCodeLine{  console.log('pipe finished', err)}
\DoxyCodeLine{\})}
\DoxyCodeLine{}
\DoxyCodeLine{setTimeout(function() \{}
\DoxyCodeLine{  dest.destroy() // when dest is closed pump will destroy source}
\DoxyCodeLine{\}, 1000) }

\end{DoxyCode}


You can use pump to pipe more than two streams together as well


\begin{DoxyCode}{0}
\DoxyCodeLine{var transform = someTransformStream()}
\DoxyCodeLine{}
\DoxyCodeLine{pump(source, transform, anotherTransform, dest, function(err) \{}
\DoxyCodeLine{  console.log('pipe finished', err)}
\DoxyCodeLine{\}) }

\end{DoxyCode}


If {\ttfamily source}, {\ttfamily transform}, {\ttfamily another\+Transform} or {\ttfamily dest} closes all of them will be destroyed.\hypertarget{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23548}{}\doxysection{License}\label{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23548}
MIT\hypertarget{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23549}{}\doxysection{Related}\label{md_sfcode_node_modules_pumpify_node_modules_pump_README_autotoc_md23549}
{\ttfamily pump} 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. 