Pass 'encoding' param of VFS' readFileSync to 'toString'

Fixes #1133
This commit is contained in:
Rocco Bruyn 2020-07-19 16:53:45 +02:00
parent fd4f285dc4
commit 812a6db941
2 changed files with 12 additions and 1 deletions

View File

@ -16,7 +16,7 @@ class VirtualFileSystem {
if (encoding) {
// return a string
return typeof data === 'string' ? data : data.toString();
return typeof data === 'string' ? data : data.toString(encoding);
}
return new Buffer(data, typeof data === 'string' ? 'base64' : undefined);

View File

@ -13,6 +13,17 @@ describe('virtual-fs', function() {
fs.fileData = {};
});
test('readFileSync', function () {
checkMissingFiles(['encoded', 'raw', 'binary']);
fs.bindFileData({
'files/binary': Buffer.from('Buffer content'),
});
const base64Data = fs.readFileSync('files/binary', 'base64');
expect(base64Data).toEqual('QnVmZmVyIGNvbnRlbnQ=');
});
test('writeFileSync', function() {
checkMissingFiles(['encoded', 'raw', 'binary']);