forked from enviPath/enviPy
Current Dev State
This commit is contained in:
38
static/js/ketcher2/node_modules/varstream/cli/json2varstream.js
generated
vendored
Executable file
38
static/js/ketcher2/node_modules/varstream/cli/json2varstream.js
generated
vendored
Executable file
@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var VarStream = require(__dirname + '/../src/VarStream')
|
||||
, fs = require('fs')
|
||||
;
|
||||
|
||||
if(process.argv[2]) {
|
||||
var scope = {}, myVarStream;
|
||||
// Reading the file
|
||||
fs.readFile(process.argv[2], function read(err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
// Parsing the JSON datas
|
||||
try {
|
||||
scope.vars = JSON.parse(data);
|
||||
} catch (err) {
|
||||
console.error('Bad JSON file', err);
|
||||
}
|
||||
// Creating the varstream
|
||||
myVarStream = new VarStream(scope, 'vars', VarStream.Writer.OPTIONS);
|
||||
// Creating the write stream
|
||||
if(!process.argv[3]) {
|
||||
myVarStream.pipe(process.stdout);
|
||||
return;
|
||||
}
|
||||
var wS = fs.createWriteStream(process.argv[3]);
|
||||
// Piping it to the ouput file
|
||||
myVarStream.pipe(wS);
|
||||
myVarStream.on('close', function() {
|
||||
console.log('Saved!');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('Usage: ' + process.argv[0] + ' ' + process.argv[1]
|
||||
+ ' path/to/input.json path/to/output.dat');
|
||||
}
|
||||
|
||||
33
static/js/ketcher2/node_modules/varstream/cli/varstream2json.js
generated
vendored
Executable file
33
static/js/ketcher2/node_modules/varstream/cli/varstream2json.js
generated
vendored
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
var VarStream = require(__dirname + '/../src/VarStream')
|
||||
, fs = require('fs')
|
||||
;
|
||||
|
||||
if(process.argv[2]) {
|
||||
var scope = {}
|
||||
, myVarStream = new VarStream(scope, 'vars')
|
||||
, rS=fs.createReadStream(process.argv[2])
|
||||
;
|
||||
|
||||
rS.pipe(myVarStream)
|
||||
.once('finish', function () {
|
||||
if(!process.argv[3]) {
|
||||
process.stdout.write(JSON.stringify(scope.vars));
|
||||
return;
|
||||
}
|
||||
fs.writeFile(process.argv[3],
|
||||
JSON.stringify(scope.vars),
|
||||
function(err) {
|
||||
if(err) {
|
||||
throw err;
|
||||
}
|
||||
console.log('Saved!');
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log('Usage: ' + process.argv[0] + ' ' + process.argv[1]
|
||||
+ ' path/to/input.dat path/to/output.json');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user