Skip to content

Commit

Permalink
Update: Make consistent internal callback names (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkemperman authored and phated committed Nov 30, 2017
1 parent 5eb006f commit c5dda86
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 35 deletions.
12 changes: 6 additions & 6 deletions lib/dest/write-contents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/dest/write-contents/write-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}

Expand Down
10 changes: 5 additions & 5 deletions lib/dest/write-contents/write-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/dest/write-contents/write-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -38,7 +38,7 @@ function writeStream(file, written) {
outStream.end(onEnd);

function onEnd(endErr) {
written(propagatedErr || endErr);
onWritten(propagatedErr || endErr);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/dest/write-contents/write-symbolic-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
18 changes: 13 additions & 5 deletions lib/src/get-contents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 3 additions & 3 deletions lib/src/get-contents/read-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -15,7 +15,7 @@ function bufferFile(file, opt, cb) {
file.contents = data;
}

cb(null, file);
onRead(null);
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/get-contents/read-dir.js
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions lib/src/get-contents/read-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
}

Expand All @@ -20,7 +20,7 @@ function streamFile(file, opt, cb) {
file.contents = file.contents.pipe(stripBom());
}

cb(null, file);
onRead(null);
}

module.exports = streamFile;
6 changes: 3 additions & 3 deletions lib/src/get-contents/read-symbolic-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down

0 comments on commit c5dda86

Please sign in to comment.