mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-27 02:24:04 -05:00
Fix unhandled error when obj or mtl is missing
This commit is contained in:
parent
3f8d2e6af7
commit
a62de758dc
@ -2,6 +2,7 @@
|
||||
const fsExtra = require("fs-extra");
|
||||
const Promise = require("bluebird");
|
||||
const readline = require("readline");
|
||||
const events = require("events");
|
||||
|
||||
module.exports = readLines;
|
||||
|
||||
@ -15,23 +16,25 @@ module.exports = readLines;
|
||||
* @private
|
||||
*/
|
||||
function readLines(path, callback) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
const stream = fsExtra.createReadStream(path);
|
||||
stream.on("error", reject);
|
||||
stream.on("end", resolve);
|
||||
const stream = fsExtra.createReadStream(path);
|
||||
return events.once(stream, "open").then(function () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
stream.on("error", reject);
|
||||
stream.on("end", resolve);
|
||||
|
||||
const lineReader = readline.createInterface({
|
||||
input: stream,
|
||||
const lineReader = readline.createInterface({
|
||||
input: stream,
|
||||
});
|
||||
|
||||
const callbackWrapper = function (line) {
|
||||
try {
|
||||
callback(line);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
lineReader.on("line", callbackWrapper);
|
||||
});
|
||||
|
||||
const callbackWrapper = function (line) {
|
||||
try {
|
||||
callback(line);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
|
||||
lineReader.on("line", callbackWrapper);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user