Açıklama Yok

cli.js 855B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var fs = require('fs');
  4. var zlib = require('zlib');
  5. var concat = require('concat-stream');
  6. var input = process.argv[2];
  7. function help() {
  8. console.log('gzip-size <input-file>');
  9. console.log('or');
  10. console.log('cat <input-file> | gzip-size');
  11. console.log('');
  12. console.log('Get the gzipped size of a file');
  13. }
  14. function report(data) {
  15. console.log(data.length);
  16. }
  17. if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) {
  18. help();
  19. return;
  20. }
  21. if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) {
  22. console.log(require('./package').version);
  23. return;
  24. }
  25. if (process.stdin.isTTY) {
  26. if (!input) {
  27. return help();
  28. }
  29. fs.createReadStream(input).pipe(zlib.createGzip()).pipe(concat(report));
  30. } else {
  31. process.stdin.pipe(zlib.createGzip()).pipe(concat(report));
  32. }