How to use the fchmod function from fs

Find comprehensive JavaScript fs.fchmod code examples handpicked from public code repositorys.

755
756
757
758
759
760
761
762
763
764
  assert.strictEqual(err.syscall, 'fchmod');
  return true;
};

common.runWithInvalidFD((fd) => {
  fs.fchmod(fd, 0o666, common.mustCall(validateError));

  assert.throws(
    () => fs.fchmodSync(fd, 0o666),
    validateError
fork icon42
star icon19
watch icon0

96
97
98
99
100
101
102
103
104
105
106
107
108
}));


fs.open(file2, 'w', common.mustCall((err, fd) => {
  assert.ifError(err);


  fs.fchmod(fd, mode_async.toString(8), common.mustCall((err) => {
    assert.ifError(err);


    if (common.isWindows) {
      assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_async);
fork icon16
star icon65
watch icon0

61
62
63
64
65
66
67
68
69
70
71


function fchmod() {
  const fs = require('fs');
  fs.writeFileSync('fs5.txt', '123', 'utf8');
  const fd = fs.openSync('fs5.txt', 'r+');
  fs.fchmod(fd, 100, () => {
    fs.unlinkSync('fs5.txt');
  });
}

fork icon0
star icon0
watch icon0

+ 2 other calls in file

43
44
45
46
47
48
49
50
51
52

{
  const file = path.join(tmpdir.path, `fchmod-async-${suffix}.txt`);
  fs.writeFileSync(file, 'test', 'utf-8');
  fs.open(file, 'w', common.mustSucceed((fd) => {
    fs.fchmod(fd, input, common.mustSucceed(() => {
      assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode);
      fs.close(fd, assert.ifError);
    }));
  }));
fork icon0
star icon0
watch icon0

+ 4 other calls in file

100
101
102
103
104
105
106
107
108
109
if (err) {
  got_error = true;
  console.error(err.stack);
  return;
}
fs.fchmod(fd, mode_async.toString(8), function(err) {
  if (err) {
    got_error = true;
  } else {
    console.log(fs.fstatSync(fd).mode);
fork icon0
star icon0
watch icon0

20
21
22
23
24
25
26
27
28
29
30
31


[false, null, {}, []].forEach((input) => {
  const errObj = {
    code: 'ERR_INVALID_ARG_TYPE',
  };
  assert.throws(() => fs.fchmod(1, input), errObj);
  assert.throws(() => fs.fchmodSync(1, input), errObj);
});


assert.throws(() => fs.fchmod(1, '123x'), {
fork icon0
star icon0
watch icon0

+ 8 other calls in file

93
94
95
96
97
98
99
100
101
102
103
    assert.strictEqual(fs.statSync(file1).mode & 0o777, mode_sync);
  }
}));


fs.open(file2, 'w', common.mustSucceed((fd) => {
  fs.fchmod(fd, mode_async.toString(8), common.mustSucceed(() => {
    if (common.isWindows) {
      assert.ok((fs.fstatSync(fd).mode & 0o777) & mode_async);
    } else {
      assert.strictEqual(fs.fstatSync(fd).mode & 0o777, mode_async);
fork icon0
star icon0
watch icon0

+ 9 other calls in file