mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-11-30 03:50:14 -05:00
29 lines
744 B
JavaScript
29 lines
744 B
JavaScript
'use strict';
|
|
const fsExtra = require('fs-extra');
|
|
const Promise = require('bluebird');
|
|
const readline = require('readline');
|
|
|
|
module.exports = readLines;
|
|
|
|
/**
|
|
* Read a file line-by-line.
|
|
*
|
|
* @param {String} path Path to the file.
|
|
* @param {Function} callback Function to call when reading each line.
|
|
* @returns {Promise} A promise when the reader is finished.
|
|
*
|
|
* @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 lineReader = readline.createInterface({
|
|
input : stream
|
|
});
|
|
lineReader.on('line', callback);
|
|
});
|
|
}
|