mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-12-02 04:50:41 -05:00
Attempt to stream JSON
This commit is contained in:
parent
280a794a10
commit
7952f70976
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
'use strict';
|
'use strict';
|
||||||
|
const json = require('big-json');
|
||||||
|
const writer = require('flush-write-stream');
|
||||||
const Cesium = require('cesium');
|
const Cesium = require('cesium');
|
||||||
const fsExtra = require('fs-extra');
|
const fsExtra = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@ -178,10 +180,8 @@ obj2gltf(objPath, options)
|
|||||||
// gltf is a glb buffer
|
// gltf is a glb buffer
|
||||||
return fsExtra.outputFile(gltfPath, gltf);
|
return fsExtra.outputFile(gltfPath, gltf);
|
||||||
}
|
}
|
||||||
const jsonOptions = {
|
|
||||||
spaces : 2
|
return streamJson(gltfPath, gltf);
|
||||||
};
|
|
||||||
return fsExtra.outputJson(gltfPath, gltf, jsonOptions);
|
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
console.timeEnd('Total');
|
console.timeEnd('Total');
|
||||||
@ -190,3 +190,35 @@ obj2gltf(objPath, options)
|
|||||||
console.log(error.message);
|
console.log(error.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function streamJson(gltfPath, gltf) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
const writeStream = fsExtra.createWriteStream(gltfPath);
|
||||||
|
|
||||||
|
const stringifyStream = json.createStringifyStream({
|
||||||
|
body: gltf
|
||||||
|
});
|
||||||
|
|
||||||
|
stringifyStream.pipe(writeStream);
|
||||||
|
|
||||||
|
writeStream.on('error', function(error) {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
writeStream.on('close', function() {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
// stringifyStream.on('data', function(str) {
|
||||||
|
// writeStream.write(str);
|
||||||
|
// });
|
||||||
|
|
||||||
|
stringifyStream.on('end', function() {
|
||||||
|
writeStream.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
stringifyStream.on('error', function(error) {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@ -26,8 +26,10 @@
|
|||||||
"node": ">=4.0.0"
|
"node": ">=4.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"big-json": "^2.0.2",
|
||||||
"bluebird": "^3.5.3",
|
"bluebird": "^3.5.3",
|
||||||
"cesium": "^1.54.0",
|
"cesium": "^1.54.0",
|
||||||
|
"flush-write-stream": "^1.1.0",
|
||||||
"fs-extra": "^7.0.1",
|
"fs-extra": "^7.0.1",
|
||||||
"jpeg-js": "^0.3.4",
|
"jpeg-js": "^0.3.4",
|
||||||
"mime": "^2.4.0",
|
"mime": "^2.4.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user