How to use the closeSync function from graceful-fs

Find comprehensive JavaScript graceful-fs.closeSync code examples handpicked from public code repositorys.

graceful-fs.closeSync is a synchronous method that closes a file descriptor.

435
436
437
438
439
440
441
442
443
444
445
446
exports.lchown = Promise.promisify(fs.lchown);
exports.lchownSync = fs.lchownSync;


// close
exports.close = Promise.promisify(fs.close);
exports.closeSync = fs.closeSync;


// copy
exports.copyDir = copyDir;
exports.copyFile = copyFile;
fork icon9
star icon48
watch icon0

+ 7 other calls in file

11
12
13
14
15
16
17
18
19
20
21
  // 550 millis past UNIX epoch
  const d = new Date(1435410243862)
  fs.writeFileSync(tmpfile, 'https://github.com/jprichardson/node-fs-extra/pull/141')
  const fd = fs.openSync(tmpfile, 'r+')
  fs.futimesSync(fd, d, d)
  fs.closeSync(fd)
  return fs.statSync(tmpfile).mtime > 1435410243000
}


function hasMillisRes (callback) {
fork icon1
star icon0
watch icon0

How does graceful-fs.closeSync work?

The graceful-fs.closeSync function is a synchronous method that closes the given file descriptor, releasing any resources associated with it. It takes a file descriptor as its argument and returns undefined. If there is an error closing the file descriptor, an exception is thrown.

73
74
75
76
77
78
79
80
81
82
83
    const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
    fs.writeSync(fdw, _buff, 0, bytesRead)
    pos += bytesRead
  }


  fs.closeSync(fdr)
  fs.closeSync(fdw)
  return fs.unlinkSync(src)
}

fork icon0
star icon1
watch icon0

64
65
66
67
68
69
70
71
72
73
74
75
}


function utimesMillisSync (path, atime, mtime) {
  const fd = fs.openSync(path, 'r+')
  fs.futimesSync(fd, atime, mtime)
  return fs.closeSync(fd)
}


module.exports = {
  hasMillisRes,
fork icon0
star icon0
watch icon0

+ 5 other calls in file

Ai Example

1
2
3
4
const fs = require("graceful-fs");

const fd = fs.openSync("/path/to/file", "r");
fs.closeSync(fd);

This code opens the file located at /path/to/file for reading, gets its file descriptor using fs.openSync(), and then synchronously closes the file descriptor using fs.closeSync().

3
4
5
6
7
8
9
10
11
12
13
14
15
const pify = require('pify');
const CpFileError = require('./cp-file-error');


const fsP = pify(fs);


exports.closeSync = fs.closeSync.bind(fs);
exports.createWriteStream = fs.createWriteStream.bind(fs);


exports.createReadStream = (path, options) => new Promise((resolve, reject) => {
	const read = fs.createReadStream(path, options);
fork icon0
star icon0
watch icon0