Read text content from different endpoints with Node.js.
Quick examples:
// Initiate the ReadFrom instance. Alternative:// var ReadFrom = require('readfrom'),// RF = new ReadFrom();var ReadFrom = new ; // Read from a file.ReadFrom; // Read from a file, line by line.ReadFrom; // Read from STDIN. (echo "This is an example." | node stdin-example.js)ReadFrom; // Read from STDIN, line by line. (cat file.txt | node stdin-by-line.js)ReadFrom; // Read from a URL.ReadFrom; // Read from a URL, line by line.ReadFrom; // Read from clipboard.ReadFrom; // Read from clipboard, line by line.ReadFrom; // Read STDOUT from child_process.spawn()// https://nodejs.org/dist/latest/docs/api/child_process.html#child_process_child_process_spawn_command_args_optionsReadFrom; // Read STDOUT from child_process.spawn(), line by line.// https://nodejs.org/dist/latest/docs/api/child_process.html#child_process_child_process_spawn_command_args_optionsReadFrom; // Create a readable stream number counter.var Readable = Readable Stream = ;Stream_read = { return { Stream; }}0 50;ReadFrom; // Create a readable stream number counter, with new lines for lineParser.var Readable = Readable Stream = ;Stream_read = { return { Stream; };}0 50;ReadFrom; // Read from a TCP socket. (echo "This is an example!" | nc 127.0.0.1 8080)// Address defaults to 0.0.0.0!ReadFromport8080 address: '127.0.0.1' ; // Read from a TCP socket, line by line. (cat file.txt | nc 127.0.0.1 8080)// Address defaults to 0.0.0.0!ReadFromport8080 address: '127.0.0.1' { console; }; // Read from a UNIX socket, line by line. (cat file.txt | nc -U /tmp/ReadFrom.sock)//// NOTE: This also works without line by line parsing, by returning with a Promise.// ReadFrom.unixSocket('/tmp/my-socket.sock').then((data) => { }).catch(() => { })ReadFrom; // Read from an SSH server. If `trim` is true, run String.trim() on the results.// If `empty` is true allow the return of empty data. 'Commands' can be a string or array.// If `combine` is passed in SSH options, the commands Array will be joined by that string. (;, &&, etc.)// {Instance}.ssh(<Commands>, <SSH Options>[, <Options>]).then(<FN>).catch(<FN>)//// NOTE: The Promise returns an Array with the following object(s):// { stdout: <String>, stderr: <String>, code: <Int>, signal: <String|Undefined> } // Supports all options for ssh2. https://github.com/mscdex/ssh2var obj = host: 'server.domain.tld' port: 22 username: 'USERNAME' password: 'PASSWORD' // privateKey: require('fs').readFileSync('/path/to/key') combine: ';';ReadFrom; // Read random X bytes from crypto.randomBytes() as a Buffer, which can be converted// with toString(<encoding>).// {Instance}.random(<Byte count>).then(<FN>).catch(<FN>)ReadFrom; // Pass `encoding` in options for random() to convert with toString BEFORE returning.ReadFrom; // Pass chunkSize to create an array of buffers. This example creates an array with 4// indexes, each containing a buffer of 256 bytes. Can be combined with `encoding`.ReadFrom;
TODO:
- Add:
ReadFrom.ssh,ReadFRom.url,ReadFrom.random- Improve/comment
ReadFrom.ssh
.
- Improve/comment
Update "quick examples" to ES6.- Create documentation.
Add tests with mocha.- Improve/finish tests for travis-ci.
- Improve/comment `./libs/SSHPromise.js'