asarFileChecker.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.checkFileInArchive = void 0;
  4. const fs_1 = require("builder-util/out/fs");
  5. const asar_1 = require("./asar");
  6. /** @internal */
  7. async function checkFileInArchive(asarFile, relativeFile, messagePrefix) {
  8. function error(text) {
  9. return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`);
  10. }
  11. let fs;
  12. try {
  13. fs = await (0, asar_1.readAsar)(asarFile);
  14. }
  15. catch (e) {
  16. throw error(`is corrupted: ${e}`);
  17. }
  18. let stat;
  19. try {
  20. stat = fs.getFile(relativeFile);
  21. }
  22. catch (e) {
  23. const fileStat = await (0, fs_1.statOrNull)(asarFile);
  24. if (fileStat == null) {
  25. throw error(`does not exist. Seems like a wrong configuration.`);
  26. }
  27. // asar throws error on access to undefined object (info.link)
  28. stat = null;
  29. }
  30. if (stat == null) {
  31. throw error(`does not exist. Seems like a wrong configuration.`);
  32. }
  33. if (stat.size === 0) {
  34. throw error(`is corrupted: size 0`);
  35. }
  36. }
  37. exports.checkFileInArchive = checkFileInArchive;
  38. //# sourceMappingURL=asarFileChecker.js.map