From 388f9928c3cc68f1c7805b1644ab44a76177be44 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 23 Jun 2016 22:35:07 -0400 Subject: [PATCH] Use different read-line library --- lib/obj.js | 22 +++++++--------------- package.json | 1 + 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/obj.js b/lib/obj.js index e5baa75..3efcb8f 100644 --- a/lib/obj.js +++ b/lib/obj.js @@ -1,8 +1,8 @@ "use strict"; var async = require('async'); +var byline = require('byline'); var fs = require('fs-extra'); var path = require('path'); -var readline = require('readline'); var loadImage = require('./image'); var Material = require('./mtl'); var Cesium = require('cesium'); @@ -163,12 +163,8 @@ function processObj(objFile, info, materials, images, done) { // f vertex//normal vertex//normal vertex//normal ... var facePattern4 = /f( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))( +(-?\d+)\/\/(-?\d+))?/; - var stream = fs.createReadStream(objFile, 'utf8'); - var reader = readline.createInterface({ - input : stream - }); - - reader.on('line', function(line) { + var stream = byline(fs.createReadStream(objFile, {encoding: 'utf8'})); + stream.on('data', function(line) { line = line.trim(); var result; if ((line.length === 0) || (line.charAt(0) === '#')) { @@ -224,7 +220,7 @@ function processObj(objFile, info, materials, images, done) { } }); - reader.on('close', function() { + stream.on('end', function() { done({ vertexCount : vertexCount, vertexArray : vertexArray, @@ -301,12 +297,8 @@ function getObjInfo(objFile, inputPath, done) { var hasNormals = false; var hasUVs = false; - var stream = fs.createReadStream(objFile, 'utf8'); - var reader = readline.createInterface({ - input : stream - }); - - reader.on('line', function(line) { + var stream = byline(fs.createReadStream(objFile, {encoding: 'utf8'})); + stream.on('data', function(line) { if (!defined(mtlPath)) { var mtllibMatches = line.match(/^mtllib.*/gm); if (mtllibMatches !== null) { @@ -331,7 +323,7 @@ function getObjInfo(objFile, inputPath, done) { } }); - reader.on('close', function() { + stream.on('end', function() { if (!hasPositions) { throw new Error('Could not process OBJ file, no positions.'); } diff --git a/package.json b/package.json index 39e0a88..9a8bc45 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ }, "dependencies": { "async": "^1.4.2", + "byline": "^4.2.1", "cesium": "^1.22.0", "fs-extra": "^0.30.0", "gltf-pipeline": "git://github.com/AnalyticalGraphicsInc/gltf-pipeline.git",