tar
Version:
tar for JavaScript
29 lines • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeFlags = void 0;
// Windows writes a small file faster through a file mapping.
const FMAP_LIMIT = 512 * 1024;
/**
* Make the function that gives the `open` flag for a new file of a
* given size.
*
* With `O_NOFOLLOW`, `open` fails if the path is a symbolic link.
* Windows does not have it. If `constants` is not set, the flag is
* `'w'`.
*/
const writeFlags = (constants, win32) => {
if (!constants)
return () => 'w';
const { O_CREAT, O_TRUNC, O_WRONLY, O_NOFOLLOW, UV_FS_O_FILEMAP } = constants;
const write = O_TRUNC | O_CREAT | O_WRONLY;
if (!win32) {
const flag = typeof O_NOFOLLOW === 'number' ? O_NOFOLLOW | write : 'w';
return () => flag;
}
if (!UV_FS_O_FILEMAP)
return () => 'w';
const fmap = UV_FS_O_FILEMAP | write;
return size => (size < FMAP_LIMIT ? fmap : 'w');
};
exports.writeFlags = writeFlags;
//# sourceMappingURL=write-flag.js.map