From b2f57d1b248895d64d19c847fbe68854d9344d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Legan=C3=A9s=20Combarro=20=22piranna?= Date: Sun, 11 Oct 2015 18:27:35 +0200 Subject: [PATCH] Use header 'mode' to detect file type if 'type' not explicitly set --- pack.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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