codekingpro/portable-devtools
115k
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.
9var __importDefault = (this && this.__importDefault) || function (mod) {
10 return (mod && mod.__esModule) ? mod : { "default": mod };
11};
12Object.defineProperty(exports, "__esModule", { value: true });
13exports.getWriteFlag = void 0;
14const fs_1 = __importDefault(require("fs"));
15const platform = process.env.__FAKE_PLATFORM__ || process.platform;
16const isWindows = platform === 'win32';
17/* c8 ignore start */
18const { O_CREAT, O_NOFOLLOW, O_TRUNC, O_WRONLY } = fs_1.default.constants;
19const 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 */
23const fMapEnabled = isWindows && !!UV_FS_O_FILEMAP;
24const fMapLimit = 512 * 1024;
25const fMapFlag = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY;
26const noFollowFlag = !isWindows && typeof O_NOFOLLOW === 'number' ?
27 O_NOFOLLOW | O_TRUNC | O_CREAT | O_WRONLY
28 : null;
29exports.getWriteFlag = noFollowFlag !== null ? () => noFollowFlag
30 : !fMapEnabled ? () => 'w'
31 : (size) => (size < fMapLimit ? fMapFlag : 'w');
32//# sourceMappingURL=get-write-flag.js.map