|
|
@ -1,7 +1,9 @@ |
|
|
|
"use strict" |
|
|
|
|
|
|
|
var fs = require('fs') |
|
|
|
, ncp = require('ncp').ncp; |
|
|
|
, ncp = require('ncp').ncp |
|
|
|
, path = require('path') |
|
|
|
, mkdir = require('./mkdir') |
|
|
|
|
|
|
|
var BUF_LENGTH = 64 * 1024; |
|
|
|
var _buff = new Buffer(BUF_LENGTH); |
|
|
@ -31,11 +33,26 @@ var copyFile = function(srcFile, destFile, cb) { |
|
|
|
return fdr.pipe(fdw); |
|
|
|
}; |
|
|
|
|
|
|
|
function copy(source, dest, callback) { |
|
|
|
if (callback) |
|
|
|
function copy(src, dest, callback) { |
|
|
|
callback = callback || function(){} |
|
|
|
|
|
|
|
fs.lstat(src, function(err, stats) { |
|
|
|
if (err) callback(err) |
|
|
|
if (!stats.isFile()) return ncp(src, dest, callback) |
|
|
|
var dir = path.dirname(dest) |
|
|
|
fs.exists(dir, function(dirExists) { |
|
|
|
if (dirExists) return ncp(src, dest, callback) |
|
|
|
mkdir.mkdirs(dir, function(err) { |
|
|
|
if (err) return callback(err) |
|
|
|
ncp(src, dest, callback) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
/*if (callback) |
|
|
|
ncp(source, dest, callback); |
|
|
|
else |
|
|
|
ncp(source, dest, function(){}); |
|
|
|
ncp(source, dest, function(){});*/ |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|