From c5dda86315e1bd66fd7960a4f264e19897225a51 Mon Sep 17 00:00:00 2001 From: Erik Kemperman Date: Wed, 29 Jun 2016 21:08:20 +0200 Subject: [PATCH] Update: Make consistent internal callback names (#182) --- lib/dest/write-contents/index.js | 12 ++++++------ lib/dest/write-contents/write-buffer.js | 6 +++--- lib/dest/write-contents/write-dir.js | 10 +++++----- lib/dest/write-contents/write-stream.js | 4 ++-- lib/dest/write-contents/write-symbolic-link.js | 6 +++--- lib/src/get-contents/index.js | 18 +++++++++++++----- lib/src/get-contents/read-buffer.js | 6 +++--- lib/src/get-contents/read-dir.js | 4 ++-- lib/src/get-contents/read-stream.js | 6 +++--- lib/src/get-contents/read-symbolic-link.js | 6 +++--- 10 files changed, 43 insertions(+), 35 deletions(-) diff --git a/lib/dest/write-contents/index.js b/lib/dest/write-contents/index.js index 6e513bde..03d0b66f 100644 --- a/lib/dest/write-contents/index.js +++ b/lib/dest/write-contents/index.js @@ -8,32 +8,32 @@ var writeSymbolicLink = require('./write-symbolic-link'); function writeContents(file, callback) { // If directory then mkdirp it if (file.isDirectory()) { - return writeDir(file, written); + return writeDir(file, onWritten); } // Stream it to disk yo if (file.isStream()) { - return writeStream(file, written); + return writeStream(file, onWritten); } // Write it as a symlink if (file.symlink) { - return writeSymbolicLink(file, written); + return writeSymbolicLink(file, onWritten); } // Write it like normal if (file.isBuffer()) { - return writeBuffer(file, written); + return writeBuffer(file, onWritten); } // If no contents then do nothing if (file.isNull()) { - return written(); + return onWritten(); } // This is invoked by the various writeXxx modules when they've finished // writing the contents. - function written(err) { + function onWritten(err) { if (isErrorFatal(err)) { return callback(err); } diff --git a/lib/dest/write-contents/write-buffer.js b/lib/dest/write-contents/write-buffer.js index 16a3469c..d4e3083b 100644 --- a/lib/dest/write-contents/write-buffer.js +++ b/lib/dest/write-contents/write-buffer.js @@ -2,7 +2,7 @@ var fo = require('../../file-operations'); -function writeBuffer(file, written) { +function writeBuffer(file, onWritten) { var opt = { mode: file.stat.mode, flag: file.flag, @@ -12,13 +12,13 @@ function writeBuffer(file, written) { function onWriteFile(writeErr, fd) { if (writeErr) { - return fo.closeFd(writeErr, fd, written); + return fo.closeFd(writeErr, fd, onWritten); } fo.updateMetadata(fd, file, onUpdate); function onUpdate(statErr) { - fo.closeFd(statErr, fd, written); + fo.closeFd(statErr, fd, onWritten); } } diff --git a/lib/dest/write-contents/write-dir.js b/lib/dest/write-contents/write-dir.js index f6e2f36b..04715e3f 100644 --- a/lib/dest/write-contents/write-dir.js +++ b/lib/dest/write-contents/write-dir.js @@ -4,12 +4,12 @@ var fs = require('graceful-fs'); var fo = require('../../file-operations'); -function writeDir(file, written) { +function writeDir(file, onWritten) { fo.mkdirp(file.path, file.stat.mode, onMkdirp); function onMkdirp(mkdirpErr) { if (mkdirpErr) { - return written(mkdirpErr); + return onWritten(mkdirpErr); } fs.open(file.path, 'r', onOpen); @@ -18,17 +18,17 @@ function writeDir(file, written) { function onOpen(openErr, fd) { // If we don't have access, just move along if (isInaccessible(openErr)) { - return fo.closeFd(null, fd, written); + return fo.closeFd(null, fd, onWritten); } if (openErr) { - return fo.closeFd(openErr, fd, written); + return fo.closeFd(openErr, fd, onWritten); } fo.updateMetadata(fd, file, onUpdate); function onUpdate(statErr) { - fo.closeFd(statErr, fd, written); + fo.closeFd(statErr, fd, onWritten); } } diff --git a/lib/dest/write-contents/write-stream.js b/lib/dest/write-contents/write-stream.js index 04c38c19..95c4c721 100644 --- a/lib/dest/write-contents/write-stream.js +++ b/lib/dest/write-contents/write-stream.js @@ -5,7 +5,7 @@ var fs = require('graceful-fs'); var fo = require('../../file-operations'); var readStream = require('../../src/get-contents/read-stream'); -function writeStream(file, written) { +function writeStream(file, onWritten) { var opt = { mode: file.stat.mode, flag: file.flag, @@ -38,7 +38,7 @@ function writeStream(file, written) { outStream.end(onEnd); function onEnd(endErr) { - written(propagatedErr || endErr); + onWritten(propagatedErr || endErr); } } diff --git a/lib/dest/write-contents/write-symbolic-link.js b/lib/dest/write-contents/write-symbolic-link.js index 954e47bc..d122c9a6 100644 --- a/lib/dest/write-contents/write-symbolic-link.js +++ b/lib/dest/write-contents/write-symbolic-link.js @@ -2,14 +2,14 @@ var fs = require('graceful-fs'); -function writeSymbolicLink(file, written) { +function writeSymbolicLink(file, onWritten) { // TODO handle symlinks properly fs.symlink(file.symlink, file.path, function(err) { if (isFatalError(err)) { - return written(err); + return onWritten(err); } - written(); + onWritten(); }); } diff --git a/lib/src/get-contents/index.js b/lib/src/get-contents/index.js index a4040784..c00eb418 100644 --- a/lib/src/get-contents/index.js +++ b/lib/src/get-contents/index.js @@ -7,25 +7,33 @@ var readBuffer = require('./read-buffer'); var readSymbolicLink = require('./read-symbolic-link'); function getContents(opt) { - return through2.obj(opt, function(file, enc, cb) { + return through2.obj(opt, function(file, enc, callback) { // Don't fail to read a directory if (file.isDirectory()) { - return readDir(file, opt, cb); + return readDir(file, opt, onRead); } // Process symbolic links included with `followSymlinks` option if (file.stat && file.stat.isSymbolicLink()) { - return readSymbolicLink(file, opt, cb); + return readSymbolicLink(file, opt, onRead); } // Read and pass full contents if (opt.buffer !== false) { - return readBuffer(file, opt, cb); + return readBuffer(file, opt, onRead); } // Don't buffer anything - just pass streams - return readStream(file, opt, cb); + return readStream(file, opt, onRead); + + // This is invoked by the various readXxx modules when they've finished + // reading the contents. + function onRead(err) { + callback(err, file); + } }); } + + module.exports = getContents; diff --git a/lib/src/get-contents/read-buffer.js b/lib/src/get-contents/read-buffer.js index 894dd9ce..13ac02ea 100644 --- a/lib/src/get-contents/read-buffer.js +++ b/lib/src/get-contents/read-buffer.js @@ -3,10 +3,10 @@ var fs = require('graceful-fs'); var stripBom = require('strip-bom'); -function bufferFile(file, opt, cb) { +function bufferFile(file, opt, onRead) { fs.readFile(file.path, function(err, data) { if (err) { - return cb(err); + return onRead(err); } if (opt.stripBOM) { @@ -15,7 +15,7 @@ function bufferFile(file, opt, cb) { file.contents = data; } - cb(null, file); + onRead(null); }); } diff --git a/lib/src/get-contents/read-dir.js b/lib/src/get-contents/read-dir.js index a800d473..38296f48 100644 --- a/lib/src/get-contents/read-dir.js +++ b/lib/src/get-contents/read-dir.js @@ -1,8 +1,8 @@ 'use strict'; -function readDir(file, opt, cb) { +function readDir(file, opt, onRead) { // Do nothing for now - cb(null, file); + onRead(null); } module.exports = readDir; diff --git a/lib/src/get-contents/read-stream.js b/lib/src/get-contents/read-stream.js index 43dc1263..6c44611b 100644 --- a/lib/src/get-contents/read-stream.js +++ b/lib/src/get-contents/read-stream.js @@ -4,9 +4,9 @@ var fs = require('graceful-fs'); var stripBom = require('strip-bom-stream'); var lazystream = require('lazystream'); -function streamFile(file, opt, cb) { +function streamFile(file, opt, onRead) { if (typeof opt === 'function') { - cb = opt; + onRead = opt; opt = {}; } @@ -20,7 +20,7 @@ function streamFile(file, opt, cb) { file.contents = file.contents.pipe(stripBom()); } - cb(null, file); + onRead(null); } module.exports = streamFile; diff --git a/lib/src/get-contents/read-symbolic-link.js b/lib/src/get-contents/read-symbolic-link.js index 794077a6..beb27c6a 100644 --- a/lib/src/get-contents/read-symbolic-link.js +++ b/lib/src/get-contents/read-symbolic-link.js @@ -2,16 +2,16 @@ var fs = require('graceful-fs'); -function readLink(file, opt, cb) { +function readLink(file, opt, onRead) { fs.readlink(file.path, function(err, target) { if (err) { - return cb(err); + return onRead(err); } // Store the link target path file.symlink = target; - return cb(null, file); + return onRead(null); }); }