Use header 'mode' to detect file type if 'type' not explicitly set
This commit is contained in:
parent
a311be903f
commit
b2f57d1b24
1 changed files with 15 additions and 1 deletions
16
pack.js
16
pack.js
|
@ -1,3 +1,4 @@
|
||||||
|
var constants = require('constants')
|
||||||
var eos = require('end-of-stream')
|
var eos = require('end-of-stream')
|
||||||
var util = require('util')
|
var util = require('util')
|
||||||
|
|
||||||
|
@ -18,6 +19,19 @@ var overflow = function(self, size) {
|
||||||
if (size) self.push(END_OF_TAR.slice(0, 512 - 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) {
|
var Sink = function(to) {
|
||||||
Writable.call(this)
|
Writable.call(this)
|
||||||
this.written = 0
|
this.written = 0
|
||||||
|
@ -83,7 +97,7 @@ Pack.prototype.entry = function(header, buffer, callback) {
|
||||||
var self = this
|
var self = this
|
||||||
|
|
||||||
if (!header.size) header.size = 0
|
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.mode) header.mode = header.type === 'directory' ? 0755 : 0644
|
||||||
if (!header.uid) header.uid = 0
|
if (!header.uid) header.uid = 0
|
||||||
if (!header.gid) header.gid = 0
|
if (!header.gid) header.gid = 0
|
||||||
|
|
Loading…
Reference in a new issue