move octals to constants for #45

This commit is contained in:
Mathias Buus 2015-11-06 15:18:52 -08:00
parent 2aa0e69c6e
commit af1abde6a4
2 changed files with 5 additions and 2 deletions

View file

@ -1,6 +1,7 @@
var ZEROS = '0000000000000000000'
var ZERO_OFFSET = '0'.charCodeAt(0)
var USTAR = 'ustar\x0000'
var MASK = parseInt('7777', 8)
var clamp = function(index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue
@ -166,7 +167,7 @@ exports.encode = function(opts) {
if (opts.linkname && Buffer.byteLength(opts.linkname) > 100) return null
buf.write(name)
buf.write(encodeOct(opts.mode & parseInt('07777', 8), 6), 100)
buf.write(encodeOct(opts.mode & MASK, 6), 100)
buf.write(encodeOct(opts.uid, 6), 108)
buf.write(encodeOct(opts.gid, 6), 116)
buf.write(encodeOct(opts.size, 11), 124)

View file

@ -9,6 +9,8 @@ var StringDecoder = require('string_decoder').StringDecoder
var headers = require('./headers')
var DMODE = parseInt('755', 8)
var FMODE = parseInt('644', 8)
var END_OF_TAR = new Buffer(1024)
END_OF_TAR.fill(0)
@ -118,7 +120,7 @@ Pack.prototype.entry = function(header, buffer, callback) {
if (!header.size) header.size = 0
if (!header.type) header.type = modeToType(header.mode)
if (!header.mode) header.mode = parseInt(header.type === 'directory' ? '0755' : '0644')
if (!header.mode) header.mode = header.type === 'directory' ? DMODE : FMODE
if (!header.uid) header.uid = 0
if (!header.gid) header.gid = 0
if (!header.mtime) header.mtime = new Date()