UI for Zipcoin Blue

index.js 715B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict';
  2. module.exports = function (cb) {
  3. var stdin = process.stdin;
  4. var ret = '';
  5. if (stdin.isTTY) {
  6. setImmediate(cb, '');
  7. return;
  8. }
  9. stdin.setEncoding('utf8');
  10. stdin.on('readable', function () {
  11. var chunk;
  12. while (chunk = stdin.read()) {
  13. ret += chunk;
  14. }
  15. });
  16. stdin.on('end', function () {
  17. cb(ret);
  18. });
  19. };
  20. module.exports.buffer = function (cb) {
  21. var stdin = process.stdin;
  22. var ret = [];
  23. var len = 0;
  24. if (stdin.isTTY) {
  25. setImmediate(cb, new Buffer(''));
  26. return;
  27. }
  28. stdin.on('readable', function () {
  29. var chunk;
  30. while (chunk = stdin.read()) {
  31. ret.push(chunk);
  32. len += chunk.length;
  33. }
  34. });
  35. stdin.on('end', function () {
  36. cb(Buffer.concat(ret, len));
  37. });
  38. };