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