diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:10:37 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:11:17 +0200 |
commit | 7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch) | |
tree | 70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/tar-stream/headers.js | |
parent | aca1143cb9eed16cf37f04e475e4257418dd18ac (diff) |
fix build issues and add typedoc
Diffstat (limited to 'node_modules/tar-stream/headers.js')
-rw-r--r-- | node_modules/tar-stream/headers.js | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/node_modules/tar-stream/headers.js b/node_modules/tar-stream/headers.js index 8c75edcc4..8aab8b561 100644 --- a/node_modules/tar-stream/headers.js +++ b/node_modules/tar-stream/headers.js @@ -1,4 +1,5 @@ var ZEROS = '0000000000000000000' +var SEVENS = '7777777777777777777' var ZERO_OFFSET = '0'.charCodeAt(0) var USTAR = 'ustar\x0000' var MASK = parseInt('7777', 8) @@ -92,7 +93,8 @@ var cksum = function (block) { var encodeOct = function (val, n) { val = val.toString(8) - return ZEROS.slice(0, n - val.length) + val + ' ' + if (val.length > n) return SEVENS.slice(0, n) + ' ' + else return ZEROS.slice(0, n - val.length) + val + ' ' } /* Copied from the node-tar repo and modified to meet @@ -130,10 +132,13 @@ function parse256 (buf) { return positive ? sum : -1 * sum } -var decodeOct = function (val, offset) { +var decodeOct = function (val, offset, length) { + val = val.slice(offset, offset + length) + offset = 0 + // If prefixed with 0x80 then parse as a base-256 integer if (val[offset] & 0x80) { - return parse256(val.slice(offset, offset + 8)) + return parse256(val) } else { // Older versions of tar can prefix with spaces while (offset < val.length && val[offset] === 32) offset++ @@ -239,17 +244,17 @@ exports.decode = function (buf) { var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET var name = decodeStr(buf, 0, 100) - var mode = decodeOct(buf, 100) - var uid = decodeOct(buf, 108) - var gid = decodeOct(buf, 116) - var size = decodeOct(buf, 124) - var mtime = decodeOct(buf, 136) + var mode = decodeOct(buf, 100, 8) + var uid = decodeOct(buf, 108, 8) + var gid = decodeOct(buf, 116, 8) + var size = decodeOct(buf, 124, 12) + var mtime = decodeOct(buf, 136, 12) var type = toType(typeflag) var linkname = buf[157] === 0 ? null : decodeStr(buf, 157, 100) var uname = decodeStr(buf, 265, 32) var gname = decodeStr(buf, 297, 32) - var devmajor = decodeOct(buf, 329) - var devminor = decodeOct(buf, 337) + var devmajor = decodeOct(buf, 329, 8) + var devminor = decodeOct(buf, 337, 8) if (buf[345]) name = decodeStr(buf, 345, 155) + '/' + name @@ -262,7 +267,7 @@ exports.decode = function (buf) { if (c === 8 * 32) return null // valid checksum - if (c !== decodeOct(buf, 148)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?') + if (c !== decodeOct(buf, 148, 8)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?') return { name: name, |