ReadFrom 
Read text content from different endpoints with Node.js.
Quick examples:
var ReadFrom = new (require('readfrom'))();
ReadFrom.file('file.txt').then((data) => {
console.log(data);
}).catch((error) => {
console.trace(error);
});
ReadFrom.file('file.txt', undefined, (line) => {
console.log('LINE: %s', line);
});
ReadFrom.stdin().then((data) =>
console.log(data);
}).catch((error) => {
console.trace(error);
});
ReadFrom.stdin(undefined, (line) => {
console.log('LINE: %s', line);
});
ReadFrom.url('https://example.com/').then((data) => {
console.log(data);
}).catch((error) => {
console.trace(error);
});
ReadFrom.url('https://example.com/', undefined, (line) => {
console.log('LINE: %s', line);
});
ReadFrom.clipboard().then((data) => {
console.log(data);
}).catch((error) => {
console.trace(error);
});
ReadFrom.clipboard(undefined, (line) => {
console.log('LINE: %s', line);
});
ReadFrom.spawn('top', ['-n 1', '-b']).then((data) => {
console.log(data);
}).catch((error) => {
console.trace(error);
});
ReadFrom.spawn('top', ['-n 1', '-b'], undefined, (line) => {
console.log('LINE: %s', line);
});
var Readable = require('stream').Readable,
Stream = new Readable;
Stream._read = ((c, m) => {
return () => { Stream.push((c <= m ? Buffer.from(String(c++)) : null)); }
})(0, 50);
ReadFrom.stream(Stream).then((data) => {
console.log(data);
}).catch((error) => {
console.trace(error);
});
var Readable = require('stream').Readable,
Stream = new Readable;
Stream._read = ((c, m) => {
return () => { Stream.push((c <= m ? Buffer.from(String([c++, "\n"].join(''))) : null)); };
})(0, 50);
ReadFrom.stream(Stream, undefined, (num) => {
console.log(num);
});
ReadFrom.port(8080, { address: '127.0.0.1' }).then((data) => {
console.log(data);
}).catch((error) => {
console.log(error);
});
ReadFrom.port(8080, { address: '127.0.0.1' }, (line) => {
console.log('LINE: %s', line);
}).then(() => {
console.log('\nFinished!');
}).catch((error) => {
console.log(error);
});
ReadFrom.unixSocket(undefined, undefined, (line) => {
console.log('LINE: %s', line);
}).then(() => {
console.log('\nFinished!');
}).catch((error) => {
console.log(error);
});
var obj = {
host: 'server.domain.tld',
port: 22,
username: 'USERNAME',
password: 'PASSWORD',
combine: ';'
};
ReadFrom.ssh(['uptime', 'notacommand', 'free -m', 'df -h', 'uname -a'], obj).then((results) => {
console.log(results);
}).catch((error) => {
console.trace(error);
});
ReadFrom.random(256).then((results) => {
console.log(results.toString('hex'));
}).catch((error) => {
console.trace(error);
});
ReadFrom.random(256, { encoding: 'base64' }).then((results) => {
console.log(results);
}).catch((error) => {
console.trace(error);
});
ReadFrom.random(1024, { chunkSize: 256 }).then((bytes) => {
console.log(bytes, bytes.length);
}).catch((error) => {
console.log(error);
});
TODO:
- Add:
ReadFrom.ssh, ReadFRom.url, ReadFrom.random
- Improve/comment
ReadFrom.ssh
.
Update "quick examples" to ES6.
- Create documentation.
Add tests with mocha.
- Improve/finish tests for travis-ci.
- Improve/comment `./libs/SSHPromise.js'