Please note the following three ways to add:
Npm. require (' child_process '). exec; = Npm . require (' FS ');
1. The original file in the private directory, with Meteor assets read content, using node. js Fs.writefile () Write, this method can only be applied to text files
varCopyFile=function() {//detects if the target file existsFS.Open(File_store_ab_path+"/aapt",' R ',function(ERR,FD) {//fs.open ()only with absolute path if(Err && err.)Code==' ENOENT ') {Console.Log(' aapt NOT exists copy ... ');FS. WriteFile (AAPT,Assets.GetText(' AAPT '),function(ERR) {if(ERR)ThrowErrConsole.Log(' It\ 's saved! ');//Fs.chmodsync (aapt,777); }); }Else{Console.Log(' AAPT exists '); } });} 2. Use node. JS FS to read and write the stream, but the target file for this method does not have permission to execute if the file is executed.
varCopyFile=function(){FS.Open(File_store_ab_path+"/aapt",' R ',function(ERR,FD) {//fs.open ()only with absolute path if(Err && err.)Code==' ENOENT ') {Console.Log(' aapt NOT exists copy ... ');//This method does not have permission to execute varreadable=FS. Createreadstream (project_root_directory+'/private/aapt ');// Create write Stream varwritable=FS. Createwritestream (File_store_ab_path+"/aapt");// to transport a stream through a pipeline readable. PIPE (writable);//I don't know why this method doesn't work, and I can't change the permissions. //fs.chmodsync (file_store_ab_path+ "/aapt", 777); }Else{Console.Log(' AAPT exists '); } });} 3. Use node. js to invoke the BASH command CP to replicate so that the copied files have execute permissions at the same timevarCopyFile=function(){FS.Open(File_store_ab_path+"/aapt",' R ', Meteor.bindenvironment (function(ERR,FD) {//fs.open ()only with absolute path if(Err && err.)Code==' ENOENT ') {Console.Log(' aapt NOT exists copy ... ');incopy=true;exec(' CP '+project_root_directory+'/private/aapt '+File_store_ab_path, Meteor.bindenvironment (function(Error, stdout, stderr) {Console.Log(' It\ 's cpoyed! ');incopy=false; })); }Else{Console.Log(' AAPT exists '); } })); }
Meteor node. js Replication (copy) file method