How to use the readSync function from graceful-fs

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

491
492
493
494
495
496
497
498
499
500
501
502
exports.symlink = Promise.promisify(fs.symlink);
exports.symlinkSync = fs.symlinkSync;


// read
exports.read = Promise.promisify(fs.read);
exports.readSync = fs.readSync;


// readdir
exports.readdir = Promise.promisify(fs.readdir);
exports.readdirSync = fs.readdirSync;
fork icon9
star icon48
watch icon0

+ 7 other calls in file

68
69
70
71
72
73
74
75
76
const stat = fs.fstatSync(fdr)
const fdw = fs.openSync(dest, flags, stat.mode)
let pos = 0

while (pos < stat.size) {
  const bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
  fs.writeSync(fdw, _buff, 0, bytesRead)
  pos += bytesRead
}
fork icon0
star icon1
watch icon0

23
24
25
26
27
28
29
30
31
var fdw = fs.openSync(destFile, 'w', stat.mode)
var bytesRead = 1
var pos = 0

while (bytesRead > 0) {
  bytesRead = fs.readSync(fdr, _buff, 0, BUF_LENGTH, pos)
  fs.writeSync(fdw, _buff, 0, bytesRead)
  pos += bytesRead
}
fork icon0
star icon0
watch icon0

27
28
29
30
31
32
33
34
35
36
37
	return fs.openSync(path, "r+");
}


function file_read(fd, offset, len) {
	var res = Buffer.alloc(len);
	var total_read = fs.readSync(fd, res, 0, len, offset);
	if(total_read < len) {
		return res.slice(0, total_read);
	} else {
		return res;
fork icon0
star icon0
watch icon0

57
58
59
60
61
62
63
64
65
66
67
};


// eslint-disable-next-line max-params
exports.readSync = (fileDescriptor, buffer, offset, length, position, path) => {
	try {
		return fs.readSync(fileDescriptor, buffer, offset, length, position);
	} catch (error) {
		throw new CpFileError(`Cannot read from \`${path}\`: ${error.message}`, error);
	}
};
fork icon0
star icon0
watch icon0

57
58
59
60
61
62
63
64
65
66
67
};


// eslint-disable-next-line max-params
exports.readSync = (fd, buffer, offset, length, position, path) => {
	try {
		return fs.readSync(fd, buffer, offset, length, position);
	} catch (err) {
		throw new CpFileError(`Cannot read from \`${path}\`: ${err.message}`, err);
	}
};
fork icon0
star icon0
watch icon0