\#through

\href{http://travis-ci.org/dominictarr/through}{\texttt{ }} \href{https://ci.testling.com/dominictarr/through}{\texttt{ }}

Easy way to create a {\ttfamily Stream} that is both {\ttfamily readable} and {\ttfamily writable}.


\begin{DoxyItemize}
\item Pass in optional {\ttfamily write} and {\ttfamily end} methods.
\item {\ttfamily through} takes care of pause/resume logic if you use {\ttfamily this.\+queue(data)} instead of `this.\+emit(\textquotesingle{}data', data){\ttfamily .}
\item {\ttfamily Use}this.\+pause(){\ttfamily and}this.\+resume(){\ttfamily to manage flow.}
\item {\ttfamily Check}this.\+paused$<$tt$>$to see current flow state. (write{\ttfamily always returns}!this.paused\`{}).
\end{DoxyItemize}

This function is the basis for most of the synchronous streams in \href{http://github.com/dominictarr/event-stream}{\texttt{ event-\/stream}}.


\begin{DoxyCode}{0}
\DoxyCodeLine{var through = require('through')}
\DoxyCodeLine{}
\DoxyCodeLine{through(function write(data) \{}
\DoxyCodeLine{    this.queue(data) //data *must* not be null}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  function end () \{ //optional}
\DoxyCodeLine{    this.queue(null)}
\DoxyCodeLine{  \}) }

\end{DoxyCode}


Or, can also be used {\itshape without} buffering on pause, use `this.\+emit(\textquotesingle{}data', data)`, and this.\+emit(\textquotesingle{}end')


\begin{DoxyCode}{0}
\DoxyCodeLine{var through = require('through')}
\DoxyCodeLine{}
\DoxyCodeLine{through(function write(data) \{}
\DoxyCodeLine{    this.emit('data', data)}
\DoxyCodeLine{    //this.pause() }
\DoxyCodeLine{  \},}
\DoxyCodeLine{  function end () \{ //optional}
\DoxyCodeLine{    this.emit('end')}
\DoxyCodeLine{  \}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_through_readme_autotoc_md30377}{}\doxysubsection{Extended Options}\label{md_sfcode_node_modules_through_readme_autotoc_md30377}
You will probably not need these 99\% of the time.\hypertarget{md_sfcode_node_modules_through_readme_autotoc_md30378}{}\doxysubsubsection{auto\+Destroy=false}\label{md_sfcode_node_modules_through_readme_autotoc_md30378}
By default, {\ttfamily through} emits close when the writable and readable side of the stream has ended. If that is not desired, set {\ttfamily auto\+Destroy=false}.


\begin{DoxyCode}{0}
\DoxyCodeLine{var through = require('through')}
\DoxyCodeLine{}
\DoxyCodeLine{//like this}
\DoxyCodeLine{var ts = through(write, end, \{autoDestroy: false\})}
\DoxyCodeLine{//or like this}
\DoxyCodeLine{var ts = through(write, end)}
\DoxyCodeLine{ts.autoDestroy = false }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_through_readme_autotoc_md30379}{}\doxysubsection{License}\label{md_sfcode_node_modules_through_readme_autotoc_md30379}
MIT / Apache2 