10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-07-03 18:06:06 +02:00

Add getTextFromFileAsync function

This commit is contained in:
Mickaël Véril 2019-09-09 15:15:39 +02:00
parent bf8449e050
commit 6a4de3f44e
2 changed files with 21 additions and 18 deletions

View File

@ -71,24 +71,7 @@ class data {
this.excitations=[];
}
static async loadAsync(file) {
return new Promise(function (resolve, reject) {
var req = new XMLHttpRequest();
req.open("GET",getFullDataPath(file), true);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {//when a good response is given do this
var text = req.responseText;
resolve(data.loadString(text));
} else {
reject({
status: req.status,
statusText: req.statusText
});
}
}
}
req.send();
});
return data.loadString(await getTextFromFileAsync(getFullDataPath(file)));
}
static loadString(text) {
// for each line with metadata

View File

@ -0,0 +1,20 @@
async function getTextFromFileAsync(file) {
return new Promise(function (resolve, reject) {
var req = new XMLHttpRequest();
req.open("GET",file, true);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {//when a good response is given do this
var text = req.responseText;
resolve(text);
} else {
reject({
status: req.status,
statusText: req.statusText
});
}
}
}
req.send();
});
}