Skip to content

Commit

Permalink
abort doc update. updates to entry data normalization and stat lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington committed Sep 24, 2014
1 parent a16fedd commit 536caa2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Inherits [Transform Stream](http://nodejs.org/api/stream.html#stream_class_strea

#### abort()

Aborts the archiving process by clearing the remaining queue and ending open streams. The instance will remain available in a read-only state.
Aborts the archiving process by clearing the remaining queue. The instance will remain available in a read-only state.

#### append(input, data)

Expand Down
45 changes: 31 additions & 14 deletions lib/modules/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,38 @@ var Archiver = module.exports = function(options) {
inherits(Archiver, Transform);

Archiver.prototype._abort = function() {
// decide how to kill off module / current stream its processing
this._queue.kill();
this._state.aborted = true;
};

Archiver.prototype._append = function(filepath, data) {
data = data || {};

var task = {
source: null,
filepath: filepath,
needsStat: true
};

if (!data.name) {
data.name = filepath;
}

data.sourcePath = filepath;

this._queue.push({
data: data,
source: null,
deferredStat: true,
filepath: filepath
});
if (data.stats === false) {
task.needsStat = false;
}

if (data.stats && data.stats instanceof fs.Stats) {
task.data = data;
task = this._updateQueueTaskWithStats(task, data.stats);
} else {
data = this._normalizeEntryData(data);
task.data = data;
}

this._queue.push(task);
};

Archiver.prototype._moduleAppend = function(source, data, callback) {
Expand Down Expand Up @@ -95,7 +107,8 @@ Archiver.prototype._normalizeEntryData = function(data, stats) {
name: null,
date: null,
mode: null,
sourcePath: null
sourcePath: null,
stats: false
});

var isDir = data.type === 'directory';
Expand All @@ -113,19 +126,21 @@ Archiver.prototype._normalizeEntryData = function(data, stats) {

if (typeof data.mode === 'number') {
data.mode &= 0777;
} else if (stats) {
} else if (stats && data.mode === null) {
data.mode = stats.mode & 0777;
} else {
} else if (data.mode === null) {
data.mode = isDir ? 0755 : 0644;
}

if (stats && data.date === null) {
data.date = stats.mtime;
} else {
data.date = util.dateify(data.date);
}

data.date = util.dateify(data.date);

data._stats = stats;
if (stats) {
data.stats = stats;
}

return data;
};
Expand Down Expand Up @@ -182,14 +197,16 @@ Archiver.prototype._onQueueTask = function(task, callback) {
}
}.bind(this);

if (task.deferredStat) {
if (task.needsStat) {
fs.stat(task.filepath, afterStat);
} else {
this._moduleAppend(task.source, task.data, afterAppend);
}
};

Archiver.prototype._updateQueueTaskWithStats = function(task, stats) {
task.needsStat = false;

if (stats.isFile()) {
task.data.type = 'file';
task.data.sourceType = 'stream';
Expand Down

0 comments on commit 536caa2

Please sign in to comment.