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

binding: mock readFileSync #378

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 19 additions & 0 deletions lib/binding.js
@@ -1,5 +1,6 @@
'use strict';

const fs = require('fs');
const path = require('path');
const File = require('./file.js');
const FileDescriptor = require('./descriptor.js');
Expand Down Expand Up @@ -433,6 +434,24 @@ Binding.prototype.openFileHandle = function (pathname, flags, mode, callback) {
});
};

/**
* This mocks the `readFileSync(path, 'utf8')` optimization
* introduced in https://github.com/nodejs/node/pull/48658.
*
* Rather than implementing the lower level behavior here we
* call `readFileSync` again but bypass the optimization.
*
* The provided flag is ignored for simplicity, as it would
* otherwise need to be transformed back intro string format.
*
* @param {string} pathname File path.
* @param {number} flags Flags.
* @return {string} The contents of the file
*/
Binding.prototype.readFileSync = function (pathname, flags /* ignored */) {
return fs.readFileSync(pathname).toString('utf8');
};

/**
* Read from a file descriptor.
* @param {string} fd File descriptor.
Expand Down