{\ttfamily from2} is a high-\/level module for creating readable streams that properly handle backpressure.

Convience wrapper for \href{http://github.com/isaacs/readable-stream}{\texttt{ readable-\/stream}}\textquotesingle{}s {\ttfamily Readable\+Stream} base class, with an API lifted from \href{http://github.com/dominictarr/from}{\texttt{ from}} and \href{http://github.com/rvagg/through2}{\texttt{ through2}}.\hypertarget{md_sfcode_node_modules_from2_README_autotoc_md10892}{}\doxysection{Usage}\label{md_sfcode_node_modules_from2_README_autotoc_md10892}
\href{https://nodei.co/npm/from2}{\texttt{ }}\hypertarget{md_sfcode_node_modules_from2_README_autotoc_md10893}{}\doxysubsection{$<$tt$>$stream = from2(\mbox{[}opts\mbox{]}, read)$<$/tt$>$}\label{md_sfcode_node_modules_from2_README_autotoc_md10893}
Where {\ttfamily opts} are the options to pass on to the {\ttfamily Readable\+Stream} constructor, and {\ttfamily read(size, next)} is called 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)} should be called when you\textquotesingle{}re ready to emit more data.
\end{DoxyItemize}

For example, here\textquotesingle{}s a readable stream that emits the contents of a given string\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var from = require('from2')}
\DoxyCodeLine{}
\DoxyCodeLine{function fromString(string) \{}
\DoxyCodeLine{  return 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_from2_README_autotoc_md10894}{}\doxysubsection{$<$tt$>$stream = from2.\+obj(\mbox{[}opts\mbox{]}, read)$<$/tt$>$}\label{md_sfcode_node_modules_from2_README_autotoc_md10894}
Shorthand for {\ttfamily from2(\{ object\+Mode\+: true \}, read)}.\hypertarget{md_sfcode_node_modules_from2_README_autotoc_md10895}{}\doxysubsection{$<$tt$>$create\+Stream = from2.\+ctor(\mbox{[}opts\mbox{]}, read)$<$/tt$>$}\label{md_sfcode_node_modules_from2_README_autotoc_md10895}
If you\textquotesingle{}re creating similar streams in quick succession you can improve performance by generating a stream {\bfseries{constructor}} that you can reuse instead of creating one-\/off streams on each call.

Takes the same options as {\ttfamily from2}, instead returning a constructor which you can use to create new streams.\hypertarget{md_sfcode_node_modules_from2_README_autotoc_md10896}{}\doxysubsection{See Also}\label{md_sfcode_node_modules_from2_README_autotoc_md10896}

\begin{DoxyItemize}
\item \href{https://github.com/binocarlos/from2-array}{\texttt{ from2-\/array}} -\/ Create a from2 stream based on an array of source values.
\item \href{https://github.com/yoshuawuyts/from2-string}{\texttt{ from2-\/string}} -\/ Create a stream from a string. Sugary wrapper around from2.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_from2_README_autotoc_md10897}{}\doxysection{License}\label{md_sfcode_node_modules_from2_README_autotoc_md10897}
MIT. See \href{http://github.com/hughsk/from2/blob/master/LICENSE.md}{\texttt{ LICENSE.\+md}} for details. 