From def68150d0e42ad870afe314cd3b7cea760e9c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Wed, 14 Oct 2015 21:32:15 +0200 Subject: [PATCH] Updated style & made utility function --- lib/dest/writeContents/utils.js | 15 +++++++++++++++ lib/dest/writeContents/writeBuffer.js | 14 ++++---------- lib/dest/writeContents/writeStream.js | 16 +++++----------- 3 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 lib/dest/writeContents/utils.js diff --git a/lib/dest/writeContents/utils.js b/lib/dest/writeContents/utils.js new file mode 100644 index 00000000..d12afbbf --- /dev/null +++ b/lib/dest/writeContents/utils.js @@ -0,0 +1,15 @@ +'use strict'; + +var fs = require('graceful-fs'); + +function utimes(writePath, stat, cb) { + if (stat.mtime) { + stat.atime = stat.atime || new Date(); + + return fs.utimes(writePath, stat.atime, stat.mtime, cb); + } + + cb(); +} + +exports.utimes = utimes; diff --git a/lib/dest/writeContents/writeBuffer.js b/lib/dest/writeContents/writeBuffer.js index 2a79add9..42a23a99 100644 --- a/lib/dest/writeContents/writeBuffer.js +++ b/lib/dest/writeContents/writeBuffer.js @@ -2,6 +2,8 @@ var fs = require('graceful-fs'); +var utimes = require('./utils').utimes; + function writeBuffer(writePath, file, cb) { var stat = file.stat; @@ -12,19 +14,11 @@ function writeBuffer(writePath, file, cb) { fs.writeFile(writePath, file.contents, opt, function(error) { - if(error) - { + if (error) { return cb(error); } - if(stat.mtime) - { - stat.atime = stat.atime || new Date(); - - return fs.utimes(writePath, stat.atime, stat.mtime, cb); - } - - cb(); + utimes(writePath, stat, cb); }); } diff --git a/lib/dest/writeContents/writeStream.js b/lib/dest/writeContents/writeStream.js index 843f062e..13ea03e0 100644 --- a/lib/dest/writeContents/writeStream.js +++ b/lib/dest/writeContents/writeStream.js @@ -1,8 +1,10 @@ 'use strict'; -var streamFile = require('../../src/getContents/streamFile'); var fs = require('graceful-fs'); +var streamFile = require('../../src/getContents/streamFile'); +var utimes = require('./utils').utimes; + function writeStream(writePath, file, cb) { var stat = file.stat; @@ -22,19 +24,11 @@ function writeStream(writePath, file, cb) { function success() { streamFile(file, {}, function(error) { - if(error) - { + if (error) { return complete(error); } - if(stat.mtime) - { - stat.atime = stat.atime || new Date(); - - return fs.utimes(writePath, stat.atime, stat.mtime, complete); - } - - complete(); + utimes(writePath, stat, complete); }); }