You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get-write-flag.js 921B

1234567891011121314151617181920
  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.
  8. // Only supported in Node v12.9.0 and above.
  9. const platform = process.env.__FAKE_PLATFORM__ || process.platform
  10. const isWindows = platform === 'win32'
  11. const fs = global.__FAKE_TESTING_FS__ || require('fs')
  12. /* istanbul ignore next */
  13. const { O_CREAT, O_TRUNC, O_WRONLY, UV_FS_O_FILEMAP = 0 } = fs.constants
  14. const fMapEnabled = isWindows && !!UV_FS_O_FILEMAP
  15. const fMapLimit = 512 * 1024
  16. const fMapFlag = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY
  17. module.exports = !fMapEnabled ? () => 'w'
  18. : size => size < fMapLimit ? fMapFlag : 'w'