How to use the writeSync function from graceful-fs

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

146
147
148
149
150
151
152
153
154
155
156


  var buf = Buffer.from(process.pid + '', 'ascii');
  fs.ftruncateSync(fd, 0);
  var pos = 0;
  while (pos < buf.length)
    pos += fs.writeSync(fd, buf, pos, buf.length - pos, pos);


  return true;
}
fork icon291
star icon672
watch icon0

548
549
550
551
552
553
554
555
556
557
558
559
exports.watchFile = fs.watchFile;
exports.unwatchFile = fs.unwatchFile;


// write
exports.write = Promise.promisify(fs.write);
exports.writeSync = fs.writeSync;


// writeFile
exports.writeFile = writeFile;
exports.writeFileSync = writeFileSync;
fork icon9
star icon48
watch icon0

+ 7 other calls in file

69
70
71
72
73
74
75
76
77
78
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
}

fs.closeSync(fdr)
fork icon0
star icon1
watch icon0

36
37
38
39
40
41
42
43
44
45
46
47
		return res;
	}
}


function file_write(fd, offset, data) {
	return fs.writeSync(fd, data, 0, data.length, offset);
}


function file_read_all(fd) {
	return fs.readFileSync(fd);
fork icon0
star icon0
watch icon0

210
211
212
213
214
215
216
217
218
219
try {
  fd = fs.openSync(tmpfile, 'w', options.mode)
  if (Buffer.isBuffer(data)) {
    fs.writeSync(fd, data, 0, data.length, 0)
  } else if (data != null) {
    fs.writeSync(fd, String(data), 0, String(options.encoding || 'utf8'))
  }
  if (options.fsync !== false) {
    fs.fsyncSync(fd)
  }
fork icon0
star icon0
watch icon0

+ 7 other calls in file

66
67
68
69
70
71
72
73
74
75
76
};


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

66
67
68
69
70
71
72
73
74
75
76
};


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