fetch.js
function streamToText(stream) {
    return new Promise((fulfill, reject) => {
        let chunks = [];
        let length = 0;
        stream.setEncoding('utf8');
        stream.on('data', chunk => {
            length += chunk.length;
            if (length > MAX_TEXT_LENGTH) {
                reject(new Error('Response is too big'));
                return;
            }
            chunks.push(chunk);
        });
        stream.on('end', () => {
            fulfill(chunks.join(''));
        });
        stream.on('error', err => {
            reject(err);
        });
    });
}
function streamToText(stream) {
    return new Promise((fulfill, reject) => {
        let chunks = [];
        let length = 0;
        stream.setEncoding('utf8');
        stream.on('data', chunk => {
            length += chunk.length;
            if (length > MAX_TEXT_LENGTH) {
                reject(new Error('Response is too big'));
                return;
            }
            chunks.push(chunk);
        });
        stream.on('end', () => {
            fulfill(chunks.join(''));
        });
        stream.on('error', err => {
            reject(err);
        });
    });
}
function streamToText ( stream ) { return new Promise ( ( fulfill , reject ) => { let chunks = [ ] ; let length = 0 ; stream . setEncoding ( 'utf8' ) ; stream . on ( 'data' , chunk => { length += chunk . length ; if ( length > MAX_TEXT_LENGTH ) { reject ( new Error ( 'Response is too big' ) ) ; return ; } chunks . push ( chunk ) ; } ) ; stream . on ( 'end' , ( ) => { fulfill ( chunks . join ( '' ) ) ; } ) ; stream . on ( 'error' , err => { reject ( err ) ; } ) ; } ) ; }
Reads the given stream and returns it as string.
Rejects if data is larger than MAX_TEXT_LENGTH.

@param {stream.Readable} stream
@returns {Promise<string>} received text
Reads the given stream and returns it as string . Rejects if data is larger than MAX_TEXT_LENGTH .