\begin{quote}
Get a stream as a string, buffer, or array \end{quote}
\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11118}{}\doxysection{Install}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11118}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install get-\/stream }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11119}{}\doxysection{Usage}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11119}

\begin{DoxyCode}{0}
\DoxyCodeLine{const fs = require('fs');}
\DoxyCodeLine{const getStream = require('get-\/stream');}
\DoxyCodeLine{}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    const stream = fs.createReadStream('unicorn.txt');}
\DoxyCodeLine{}
\DoxyCodeLine{    console.log(await getStream(stream));}
\DoxyCodeLine{    /*}
\DoxyCodeLine{                  ,,))))))));,}
\DoxyCodeLine{               \_\_)))))))))))))),}
\DoxyCodeLine{    \(\backslash\)|/       -\/\(\backslash\)(((((''''((((((((.}
\DoxyCodeLine{    -\/*-\/==//////((''  .     `)))))),}
\DoxyCodeLine{    /|\(\backslash\)      ))| o    ;-\/.    '(((((                                  ,(,}
\DoxyCodeLine{             ( `|    /  )    ;))))'                               ,\_))\string^;(\string~}
\DoxyCodeLine{                |   |   |   ,))((((\_     \_\_\_\_\_-\/-\/-\/-\/-\/-\/\string~\string~\string~-\/.        \%,;(;(>';'\string~}
\DoxyCodeLine{                o\_);   ;    )))(((` \string~-\/-\/-\/\string~  `::           \(\backslash\)      \%\%\string~\string~)(v;(`('\string~}
\DoxyCodeLine{                      ;    ''''````         `:       `:::|\(\backslash\),\_\_,\%\%    );`'; \string~}
\DoxyCodeLine{                     |   \_                )     /      `:|`-\/-\/-\/-\/'     `-\/'}
\DoxyCodeLine{               \_\_\_\_\_\_/\(\backslash\)/\string~    |                 /        /}
\DoxyCodeLine{             /\string~;;.\_\_\_\_/;;'  /          \_\_\_-\/-\/,-\/(   `;;;/}
\DoxyCodeLine{            / //  \_;\_\_\_\_\_\_;'-\/-\/-\/-\/-\/-\/\string~\string~\string~\string~\string~    /;;/\(\backslash\)    /}
\DoxyCodeLine{           //  | |                        / ;   \(\backslash\);;,\(\backslash\)}
\DoxyCodeLine{          (<\_  | ;                      /',/-\/-\/-\/-\/-\/'  \_>}
\DoxyCodeLine{           \(\backslash\)\_| ||\_                     //\string~;\string~\string~\string~\string~\string~\string~\string~\string~\string~}
\DoxyCodeLine{               `\(\backslash\)\_|                   (,\string~\string~}
\DoxyCodeLine{                                       \(\backslash\)\string~\(\backslash\)}
\DoxyCodeLine{                                        \string~\string~}
\DoxyCodeLine{    */}
\DoxyCodeLine{\})(); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11120}{}\doxysection{API}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11120}
The methods returns a promise that resolves when the {\ttfamily end} event fires on the stream, indicating that there is no more data to be read. The stream is switched to flowing mode.\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11121}{}\doxysubsection{get\+Stream(stream, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11121}
Get the {\ttfamily stream} as a string.\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11122}{}\doxysubsubsection{options}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11122}
Type\+: {\ttfamily Object}\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11123}{}\doxyparagraph{encoding}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11123}
Type\+: {\ttfamily string}~\newline
 Default\+: {\ttfamily utf8}

\href{https://nodejs.org/api/buffer.html\#buffer_buffer}{\texttt{ Encoding}} of the incoming stream.\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11124}{}\doxyparagraph{max\+Buffer}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11124}
Type\+: {\ttfamily number}~\newline
 Default\+: {\ttfamily Infinity}

Maximum length of the returned string. If it exceeds this value before the stream ends, the promise will be rejected with a {\ttfamily get\+Stream.\+Max\+Buffer\+Error} error.\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11125}{}\doxysubsection{get\+Stream.\+buffer(stream, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11125}
Get the {\ttfamily stream} as a buffer.

It honors the {\ttfamily max\+Buffer} option as above, but it refers to byte length rather than string length.\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11126}{}\doxysubsection{get\+Stream.\+array(stream, \mbox{[}options\mbox{]})}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11126}
Get the {\ttfamily stream} as an array of values.

It honors both the {\ttfamily max\+Buffer} and {\ttfamily encoding} options. The behavior changes slightly based on the encoding chosen\+:


\begin{DoxyItemize}
\item When {\ttfamily encoding} is unset, it assumes an \href{https://nodesource.com/blog/understanding-object-streams/}{\texttt{ object mode stream}} and collects values emitted from {\ttfamily stream} unmodified. In this case {\ttfamily max\+Buffer} refers to the number of items in the array (not the sum of their sizes).
\item When {\ttfamily encoding} is set to {\ttfamily buffer}, it collects an array of buffers. {\ttfamily max\+Buffer} refers to the summed byte lengths of every buffer in the array.
\item When {\ttfamily encoding} is set to anything else, it collects an array of strings. {\ttfamily max\+Buffer} refers to the summed character lengths of every string in the array.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11127}{}\doxysection{Errors}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11127}
If the input stream emits an {\ttfamily error} event, the promise will be rejected with the error. The buffered data will be attached to the {\ttfamily buffered\+Data} property of the error.


\begin{DoxyCode}{0}
\DoxyCodeLine{(async () => \{}
\DoxyCodeLine{    try \{}
\DoxyCodeLine{        await getStream(streamThatErrorsAtTheEnd('unicorn'));}
\DoxyCodeLine{    \} catch (error) \{}
\DoxyCodeLine{        console.log(error.bufferedData);}
\DoxyCodeLine{        //=> 'unicorn'}
\DoxyCodeLine{    \}}
\DoxyCodeLine{\})() }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11128}{}\doxysection{FAQ}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11128}
\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11129}{}\doxysubsection{How is this different from $<$a href=\char`\"{}https\+://github.\+com/maxogden/concat-\/stream\char`\"{}$>$$<$tt$>$concat-\/stream$<$/tt$>$$<$/a$>$?}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11129}
This module accepts a stream instead of being one and returns a promise instead of using a callback. The API is simpler and it only supports returning a string, buffer, or array. It doesn\textquotesingle{}t have a fragile type inference. You explicitly choose what you want. And it doesn\textquotesingle{}t depend on the huge {\ttfamily readable-\/stream} package.\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11130}{}\doxysection{Related}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11130}

\begin{DoxyItemize}
\item \href{https://github.com/sindresorhus/get-stdin}{\texttt{ get-\/stdin}} -\/ Get stdin as a string or buffer
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_get_stream_readme_autotoc_md11131}{}\doxysection{License}\label{md_sfcode_node_modules_get_stream_readme_autotoc_md11131}
MIT © \href{https://sindresorhus.com}{\texttt{ Sindre Sorhus}} 