lib/fileSystem.js
function copyFile(sourceFilePath, destinationFilePath, callback) {
  var onError = function(error) {
    callback(error);
  };

  var safecopy = function(sourceFilePath, destinationFilePath, callback) {
    if (sourceFilePath && destinationFilePath && callback) {
      try {
        var is = fs.createReadStream(sourceFilePath);
        var os = fs.createWriteStream(destinationFilePath);

        is.on('error', onError);
        os.on('error', onError);

        is.on('end', function() {
          os.end();
        });

        os.on('finish', function() {
          callback();
        });

        is.pipe(os);
      } catch (e) {
        callback(new Error(e.message));
      }
    } else callback(new Error('File path not defined'));
  };

  var pathDir = path.dirname(destinationFilePath);

  this.mkdir(pathDir,
    function(error) {
      if (error) callback(error);
      else safecopy(sourceFilePath, destinationFilePath, callback);
    }
  );
}
function copyFile(sourceFilePath, destinationFilePath, callback) {
  var onError = function(error) {
    callback(error);
  };

  var safecopy = function(sourceFilePath, destinationFilePath, callback) {
    if (sourceFilePath && destinationFilePath && callback) {
      try {
        var is = fs.createReadStream(sourceFilePath);
        var os = fs.createWriteStream(destinationFilePath);

        is.on('error', onError);
        os.on('error', onError);

        is.on('end', function() {
          os.end();
        });

        os.on('finish', function() {
          callback();
        });

        is.pipe(os);
      } catch (e) {
        callback(new Error(e.message));
      }
    } else callback(new Error('File path not defined'));
  };

  var pathDir = path.dirname(destinationFilePath);

  this.mkdir(pathDir,
    function(error) {
      if (error) callback(error);
      else safecopy(sourceFilePath, destinationFilePath, callback);
    }
  );
}
function copyFile ( sourceFilePath , destinationFilePath , callback ) { var onError = function ( error ) { callback ( error ) ; } ; var safecopy = function ( sourceFilePath , destinationFilePath , callback ) { if ( sourceFilePath && destinationFilePath && callback ) { try { var is = fs . createReadStream ( sourceFilePath ) ; var os = fs . createWriteStream ( destinationFilePath ) ; is . on ( 'error' , onError ) ; os . on ( 'error' , onError ) ; is . on ( 'end' , function ( ) { os . end ( ) ; } ) ; os . on ( 'finish' , function ( ) { callback ( ) ; } ) ; is . pipe ( os ) ; } catch ( e ) { callback ( new Error ( e . message ) ) ; } } else callback ( new Error ( 'File path not defined' ) ) ; } ; var pathDir = path . dirname ( destinationFilePath ) ; this . mkdir ( pathDir , function ( error ) { if ( error ) callback ( error ) ; else safecopy ( sourceFilePath , destinationFilePath , callback ) ; } ) ; }
Copies a file.

If directory does not exist it will be automatically created.

@method copyFile
@private
@static
@async
@param {String} sourceFilePath Path of the file
@param {String} destinationFilePath Final path of the file
@param {Function} callback The function to call when done
- **Error** The error if an error occurred, null otherwise
Copies a file .