Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,11 @@ fs.readSync = function(fd, buffer, offset, length, position) {
if (!isUint32(position))
position = -1;

return binding.read(fd, buffer, offset, length, position);
const ctx = {};
const result = binding.read(fd, buffer, offset, length, position,
undefined, ctx);
handleErrorFromBinding(ctx);
return result;
};

// usage:
Expand Down Expand Up @@ -631,6 +635,8 @@ Object.defineProperty(fs.write, internalUtil.customPromisifyArgs,
// fs.writeSync(fd, string[, position[, encoding]]);
fs.writeSync = function(fd, buffer, offset, length, position) {
validateUint32(fd, 'fd');
const ctx = {};
let result;
if (isUint8Array(buffer)) {
if (position === undefined)
position = null;
Expand All @@ -639,13 +645,18 @@ fs.writeSync = function(fd, buffer, offset, length, position) {
if (typeof length !== 'number')
length = buffer.length - offset;
validateOffsetLengthWrite(offset, length, buffer.byteLength);
return binding.writeBuffer(fd, buffer, offset, length, position);
result = binding.writeBuffer(fd, buffer, offset, length, position,
undefined, ctx);
} else {
if (typeof buffer !== 'string')
buffer += '';
if (offset === undefined)
offset = null;
result = binding.writeString(fd, buffer, offset, length,
undefined, ctx);
}
if (typeof buffer !== 'string')
buffer += '';
if (offset === undefined)
offset = null;
return binding.writeString(fd, buffer, offset, length, position);
handleErrorFromBinding(ctx);
return result;
};

fs.rename = function(oldPath, newPath, callback) {
Expand Down Expand Up @@ -1000,7 +1011,9 @@ fs.fchmodSync = function(fd, mode) {
validateUint32(mode, 'mode');
if (mode < 0 || mode > 0o777)
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'mode');
return binding.fchmod(fd, mode);
const ctx = {};
binding.fchmod(fd, mode, undefined, ctx);
handleErrorFromBinding(ctx);
};

if (constants.O_SYMLINK !== undefined) {
Expand Down Expand Up @@ -1104,7 +1117,9 @@ fs.fchownSync = function(fd, uid, gid) {
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');

return binding.fchown(fd, uid, gid);
const ctx = {};
binding.fchown(fd, uid, gid, undefined, ctx);
handleErrorFromBinding(ctx);
};

fs.chown = function(path, uid, gid, callback) {
Expand Down Expand Up @@ -1168,7 +1183,9 @@ fs.futimesSync = function(fd, atime, mtime) {
validateUint32(fd, 'fd');
atime = toUnixTimestamp(atime, 'atime');
mtime = toUnixTimestamp(mtime, 'mtime');
binding.futimes(fd, atime, mtime);
const ctx = {};
binding.futimes(fd, atime, mtime, undefined, ctx);
handleErrorFromBinding(ctx);
};

function writeAll(fd, isUserFd, buffer, offset, length, position, callback) {
Expand Down
Loading