Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in writeBuffer call and expose getDescriptorById #311

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/binding.js
Expand Up @@ -855,7 +855,7 @@ Binding.prototype.writeString = function(
callback(err, written, returned && string);
};
}
return this.writeBuffer(fd, buffer, 0, string.length, position, wrapper, ctx);
return this.writeBuffer(fd, buffer, 0, buffer.length, position, wrapper, ctx);
};

/**
Expand Down
15 changes: 15 additions & 0 deletions lib/index.js
Expand Up @@ -169,6 +169,21 @@ exports.restore = function() {
restoreCreateWriteStream();
};

/**
* Get a file descriptor object by a mocked file descriptor number returned by mock-fs.
* Cannot work with a real file descriptor number
* @param {number} fd File descriptor number (returned by mock-fs)
* @returns {FileDescriptor} File descriptor object
*/
exports.getDescriptorById = function(fd) {
/** @type {Binding} */
const binding = realBinding._mockedBinding;
if (!binding) {
return null;
}
return binding.getDescriptorById(fd);
};

/**
* Create a file factory.
*/
Expand Down