get-file-size.js 922 B

1234567891011121314151617181920212223242526272829
  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. var __importDefault = (this && this.__importDefault) || function (mod) {
  9. return (mod && mod.__esModule) ? mod : { "default": mod };
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. exports.getFileSize = void 0;
  13. const fs_extra_1 = __importDefault(require("fs-extra"));
  14. const errors_1 = require("./errors");
  15. function getFileSize(file) {
  16. try {
  17. const stat = fs_extra_1.default.statSync(file);
  18. if (!stat.isFile()) {
  19. return null;
  20. }
  21. return stat.size;
  22. }
  23. catch (err) {
  24. throw new Error(errors_1.errors['unable-to-get-file-size'] +
  25. ` '${err instanceof Error && err.message ? err.message : ''}'`);
  26. }
  27. }
  28. exports.getFileSize = getFileSize;