Skip to content

fix: utf8 issue #2113

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

Open
wants to merge 1 commit into
base: develop
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/15utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,26 @@ async function fetchData(path, success, error, async) {
}

function getData(path, success, error) {
return _fetch(path)
.then(response => response.text())
.then(txt => {
success(txt);
})
.catch(e => {
if (error) return error(e);
console.error(e);
throw e;
});
}

async function fetchBinaryData(path, success, error, async) {
if (async) {
return getBinaryData(path, success, error);
}
return await getBinaryData(path, success, error);
}

function getBinaryData(path, success, error) {
return _fetch(path)
.then(response => response.arrayBuffer())
.then(buf => {
Expand Down Expand Up @@ -481,7 +501,7 @@ var loadBinaryFile = (utils.loadBinaryFile = function (
fs = require('fs');

if (/^[a-z]+:\/\//i.test(path)) {
fetchData(path, success, error, runAsync);
fetchBinaryData(path, success, error, runAsync);
} else {
if (runAsync) {
fs.readFile(path, function (err, data) {
Expand Down
2 changes: 1 addition & 1 deletion test/test157.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Test 157 - json()', function () {
it('1. Load text data from file async', function (done) {
alasql('select * from json("' + __dirname + '/test157.json")', [], function (res) {
// console.log(13,res);
assert.deepEqual(res, [{a: 1}, {a: 2}]);
assert.deepEqual(res, [{a: 1}, {a: 2}, {c: '😂'}]);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/test157.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"a": 1}, {"a": 2}]
[{"a": 1}, {"a": 2}, {"c": "😂"}]
Loading