helpers.js
function readSocket(socket, numberOfBytes) {
    return new Promise((resolve, reject) => {
        let completed = createSimplePromiseCompletedAction(resolve, reject);
        try {
            let buff = socket.read(numberOfBytes);
            if (null === buff) {
                socket.once('readable', function () {
                    readSocket(socket, numberOfBytes).then((b) => {
                        completed(null, b);
                    }, (err) => {
                        completed(err);
                    });
                });
            }
            else {
                completed(null, buff);
            }
        }
        catch (e) {
            completed(e);
        }
    });
}
function readSocket(socket, numberOfBytes) {
    return new Promise((resolve, reject) => {
        let completed = createSimplePromiseCompletedAction(resolve, reject);
        try {
            let buff = socket.read(numberOfBytes);
            if (null === buff) {
                socket.once('readable', function () {
                    readSocket(socket, numberOfBytes).then((b) => {
                        completed(null, b);
                    }, (err) => {
                        completed(err);
                    });
                });
            }
            else {
                completed(null, buff);
            }
        }
        catch (e) {
            completed(e);
        }
    });
}
function readSocket ( socket , numberOfBytes ) { return new Promise ( ( resolve , reject ) => { let completed = createSimplePromiseCompletedAction ( resolve , reject ) ; try { let buff = socket . read ( numberOfBytes ) ; if ( null === buff ) { socket . once ( 'readable' , function ( ) { readSocket ( socket , numberOfBytes ) . then ( ( b ) => { completed ( null , b ) ; } , ( err ) => { completed ( err ) ; } ) ; } ) ; } else { completed ( null , buff ) ; } } catch ( e ) { completed ( e ) ; } } ) ; }
Reads a number of bytes from a socket.

@param {net.Socket} socket The socket.
@param {Number} [numberOfBytes] The amount of bytes to read.

@return {Promise<Buffer>} The promise.
Reads a number of bytes from a socket .