UNPKG

restify

Version:
35 lines (30 loc) 921 B
// The package "should" must be installed: // `npm install should` var parse = require('../lib'); require('should'); var output = []; // Create the parser var parser = parse({delimiter: ':'}); // Use the writable stream api parser.on('readable', function(){ var record; while (record = parser.read()) { output.push(record); } }); // Catch any error parser.on('error', function(err){ console.log(err.message); }); // When we are done, test that the parsed output matched what expected parser.on('finish', function(){ output.should.eql([ [ 'root','x','0','0','root','/root','/bin/bash' ], [ 'someone','x','1022','1022','a funny cat','/home/someone','/bin/bash' ] ]); }); // Now that setup is done, write data to the stream parser.write("root:x:0:0:root:/root:/bin/bash\n"); parser.write("someone:x:1022:1022:a funny cat:/home/someone:/bin/bash\n"); // Close the readable stream parser.end();