Skip to content

Commit

Permalink
binding: mock readFileSync
Browse files Browse the repository at this point in the history
  • Loading branch information
Rugvip committed Sep 5, 2023
1 parent 6e84d5b commit f0a4445
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit f0a4445

Please sign in to comment.