You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 15, 2021. It is now read-only.
Automatically switch to streaming mode when the input file is
over 150kB or manually enable with --stream or -x.
Not made the default mode since it is actually slower for files
that can be parsed using the default method without running out
of available memory. The hard limit for that is around 200kB on
my machine.
Refs #27
'use strict';var_index=require('../lib/index');var_index2=_interopRequireDefault(_index);var_fs=require('fs');var_path=require('path');function_interopRequireDefault(obj){returnobj&&obj.__esModule?obj:{default:obj};}varaliases={o:'output',v:'version',h:'help',x:'stream'};varargs=resolveArgs(process.argv.slice(2));varerror=functionerror(err){console.error(err);process.exit(1);};vardone=checkThen(function(){process.exit(0);});if(args['version']){console.log('sqlite-parser v1.0.0-beta2');process.exit(0);}if(args['help']||args._.length===0){console.log('Usage:\tsqlite-parser [infile]\n');console.log('Option\t\t\tAlias\tDescription');console.log('--output [outfile]\t-o\tWrite output to a file instead of stdout');console.log('--stream\t\t-x\tEnable streaming mode (default: infile >150kB)');console.log('--version\t\t-v\tGet current parser version');process.exit(0);}varstreaming=args['stream'];varinput=(0,_path.normalize)(args._[0]);varoutput=args['output'];if(output){output=(0,_path.normalize)(output);}(0,_fs.stat)(input,checkThen(function(_ref){varsize=_ref.size;if(size/1000>=150){streaming=true;}varstartStream=streaming?streamParser:standardParser;if(output){(function(){varoutDir=(0,_path.dirname)(output);(0,_fs.stat)(outDir,checkThen(startStream,function(){(0,_fs.mkdir)(outDir,startStream);}));})();}else{startStream();}}));functionresolveArgs(argv){varargs={_:[]};varlast=null;varisNewArg=functionisNewArg(arg){return!arg||arg.indexOf('-')===0;};for(vari=0;i<argv.length;i+=1){vararg=argv[i];if(isNewArg(arg)){varcur=arg.indexOf('--')!==-1?arg.slice(2):aliases[arg.slice(1)];varpeek=argv.length-1!==i?argv[i+1]:null;varpeekNew=isNewArg(peek);args[cur]=peekNew?true:peek;if(!peekNew){i+=1;}}else{args._.push(arg);}}returnargs;}functioncheckThen(){varresCallback=arguments.length>0&&arguments[0]!==undefined?arguments[0]:done;varerrCallback=arguments.length>1&&arguments[1]!==undefined?arguments[1]:error;returnfunction(err,result){if(err){returnerrCallback(err);}resCallback(result);};}functionstreamParser(){varparserTransform=_index2.default.createParser();varsingleNodeTransform=_index2.default.createStitcher();varreadStream=(0,_fs.createReadStream)(input);varwriteStream=output?(0,_fs.createWriteStream)(output):process.stdout;readStream.pipe(parserTransform);parserTransform.pipe(singleNodeTransform);singleNodeTransform.pipe(writeStream);parserTransform.on('error',error);singleNodeTransform.on('error',error);writeStream.on('finish',done);}functionstandardParser(){(0,_fs.readFile)(input,'utf8',checkThen(function(data){(0,_index2.default)(data,checkThen(function(ast){varresult=void0;try{result=JSON.stringify(ast,null,2);}catch(e){returnerror(e);}if(output){(0,_fs.writeFile)(output,result,checkThen(done));}else{process.stdout.write(result+'\n');done();}}));}));};
0 commit comments