Merge pull request #1134 from rokkie/bugfix/pass-encoding-param

Pass 'encoding' param of VFS' readFileSync to 'toString'
This commit is contained in:
Luiz Américo 2020-07-19 20:44:21 -03:00 committed by GitHub
commit 3f36801b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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']);