Use header 'mode' to detect file type if 'type' not explicitly set

This commit is contained in:
Jesús Leganés Combarro "piranna 2015-10-11 18:27:35 +02:00
parent a311be903f
commit b2f57d1b24

16
pack.js
View file

@ -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