get-file-size.js 509 B

1234567891011121314151617181920212223242526
  1. "use strict";
  2. /*
  3. Copyright 2018 Google LLC
  4. Use of this source code is governed by an MIT-style
  5. license that can be found in the LICENSE file or at
  6. https://opensource.org/licenses/MIT.
  7. */
  8. const fs = require('fs');
  9. const errors = require('./errors');
  10. module.exports = file => {
  11. try {
  12. const stat = fs.statSync(file);
  13. if (!stat.isFile()) {
  14. return null;
  15. }
  16. return stat.size;
  17. } catch (err) {
  18. throw new Error(errors['unable-to-get-file-size'] + ` '${err.message}'`);
  19. }
  20. };