diff --git a/pack.js b/pack.js index 1de304c..c9aade5 100644 --- a/pack.js +++ b/pack.js @@ -1,3 +1,4 @@ +var constants = require('constants') var eos = require('end-of-stream') var util = require('util') @@ -18,6 +19,19 @@ var overflow = function(self, size) { if (size) self.push(END_OF_TAR.slice(0, 512 - size)) } +function mode2type(mode) +{ + switch (mode & constants.S_IFMT) { + case constants.S_IFBLK: return 'block-device' + case constants.S_IFCHR: return 'character-device' + case constants.S_IFDIR: return 'directory' + case constants.S_IFIFO: return 'fifo' + case constants.S_IFLNK: return 'symlink' + } + + return 'file' +} + var Sink = function(to) { Writable.call(this) this.written = 0 @@ -83,7 +97,7 @@ Pack.prototype.entry = function(header, buffer, callback) { var self = this if (!header.size) header.size = 0 - if (!header.type) header.type = 'file' + if (!header.type) header.type = mode2type(header.mode) if (!header.mode) header.mode = header.type === 'directory' ? 0755 : 0644 if (!header.uid) header.uid = 0 if (!header.gid) header.gid = 0