write-file.js 507 B

12345678910111213141516171819
  1. const fs = require('./fs.js')
  2. const getOptions = require('./common/get-options.js')
  3. const owner = require('./common/owner.js')
  4. const writeFile = async (file, data, opts) => {
  5. const options = getOptions(opts, {
  6. copy: ['encoding', 'mode', 'flag', 'signal', 'owner'],
  7. wrap: 'encoding',
  8. })
  9. const { uid, gid } = await owner.validate(file, options.owner)
  10. const result = await fs.writeFile(file, data, options)
  11. await owner.update(file, uid, gid)
  12. return result
  13. }
  14. module.exports = writeFile