d987730a64fdae31c80344a9769fd2dbe1c9f6ee1792e9e11f43c2c8187f7c00eaedb7e041ecc08015a38085a5ca63bd339cc8f5501d0920b6467175f78aee 1.3 KB

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. // Get the appropriate flag to use for creating files
  3. // We use fmap on Windows platforms for files less than
  4. // 512kb. This is a fairly low limit, but avoids making
  5. // things slower in some cases. Since most of what this
  6. // library is used for is extracting tarballs of many
  7. // relatively small files in npm packages and the like,
  8. // it can be a big boost on Windows platforms.
  9. var __importDefault = (this && this.__importDefault) || function (mod) {
  10. return (mod && mod.__esModule) ? mod : { "default": mod };
  11. };
  12. Object.defineProperty(exports, "__esModule", { value: true });
  13. exports.getWriteFlag = void 0;
  14. const fs_1 = __importDefault(require("fs"));
  15. const platform = process.env.__FAKE_PLATFORM__ || process.platform;
  16. const isWindows = platform === 'win32';
  17. /* c8 ignore start */
  18. const { O_CREAT, O_TRUNC, O_WRONLY } = fs_1.default.constants;
  19. const UV_FS_O_FILEMAP = Number(process.env.__FAKE_FS_O_FILENAME__) ||
  20. fs_1.default.constants.UV_FS_O_FILEMAP ||
  21. 0;
  22. /* c8 ignore stop */
  23. const fMapEnabled = isWindows && !!UV_FS_O_FILEMAP;
  24. const fMapLimit = 512 * 1024;
  25. const fMapFlag = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY;
  26. exports.getWriteFlag = !fMapEnabled ?
  27. () => 'w'
  28. : (size) => (size < fMapLimit ? fMapFlag : 'w');
  29. //# sourceMappingURL=get-write-flag.js.map