Meteor node. js Replication (copy) file method

Source: Internet
Author: User

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 time
varCopyFile=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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.