Skip to content

Commit 0084b67

Browse files
committed
fix: utf8 issue
1 parent 0d5c981 commit 0084b67

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/15utility.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,26 @@ async function fetchData(path, success, error, async) {
442442
}
443443

444444
function getData(path, success, error) {
445+
return _fetch(path)
446+
.then(response => response.text())
447+
.then(txt => {
448+
success(txt);
449+
})
450+
.catch(e => {
451+
if (error) return error(e);
452+
console.error(e);
453+
throw e;
454+
});
455+
}
456+
457+
async function fetchBinaryData(path, success, error, async) {
458+
if (async) {
459+
return getBinaryData(path, success, error);
460+
}
461+
return await getBinaryData(path, success, error);
462+
}
463+
464+
function getBinaryData(path, success, error) {
445465
return _fetch(path)
446466
.then(response => response.arrayBuffer())
447467
.then(buf => {
@@ -481,7 +501,7 @@ var loadBinaryFile = (utils.loadBinaryFile = function (
481501
fs = require('fs');
482502

483503
if (/^[a-z]+:\/\//i.test(path)) {
484-
fetchData(path, success, error, runAsync);
504+
fetchBinaryData(path, success, error, runAsync);
485505
} else {
486506
if (runAsync) {
487507
fs.readFile(path, function (err, data) {

test/test157.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Test 157 - json()', function () {
1010
it('1. Load text data from file async', function (done) {
1111
alasql('select * from json("' + __dirname + '/test157.json")', [], function (res) {
1212
// console.log(13,res);
13-
assert.deepEqual(res, [{a: 1}, {a: 2}]);
13+
assert.deepEqual(res, [{a: 1}, {a: 2}, {c: '\u1234'}]);
1414
done();
1515
});
1616
});

test/test157.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"a": 1}, {"a": 2}]
1+
[{"a": 1}, {"a": 2}, {"c": "\u1234"}]

0 commit comments

Comments
 (0)