Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tar-stream

Package Overview
Dependencies
Maintainers
2
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tar-stream - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

110

headers.js
var ZEROS = '0000000000000000000'
var ZERO_OFFSET = '0'.charCodeAt(0)
var USTAR = 'ustar\x0000'
var MASK = parseInt('7777', 8)
var clamp = function(index, len, defaultValue) {
var clamp = function (index, len, defaultValue) {
if (typeof index !== 'number') return defaultValue

@@ -15,29 +16,29 @@ index = ~~index // Coerce to integer.

var toType = function(flag) {
var toType = function (flag) {
switch (flag) {
case 0:
return 'file'
return 'file'
case 1:
return 'link'
return 'link'
case 2:
return 'symlink'
return 'symlink'
case 3:
return 'character-device'
return 'character-device'
case 4:
return 'block-device'
return 'block-device'
case 5:
return 'directory'
return 'directory'
case 6:
return 'fifo'
return 'fifo'
case 7:
return 'contiguous-file'
return 'contiguous-file'
case 72:
return 'pax-header'
return 'pax-header'
case 55:
return 'pax-global-header'
return 'pax-global-header'
case 27:
return 'gnu-long-link-path'
return 'gnu-long-link-path'
case 28:
case 30:
return 'gnu-long-path'
return 'gnu-long-path'
}

@@ -48,22 +49,22 @@

var toTypeflag = function(flag) {
var toTypeflag = function (flag) {
switch (flag) {
case 'file':
return 0
return 0
case 'link':
return 1
return 1
case 'symlink':
return 2
return 2
case 'character-device':
return 3
return 3
case 'block-device':
return 4
return 4
case 'directory':
return 5
return 5
case 'fifo':
return 6
return 6
case 'contiguous-file':
return 7
return 7
case 'pax-header':
return 72
return 72
}

@@ -74,3 +75,3 @@

var alloc = function(size) {
var alloc = function (size) {
var buf = new Buffer(size)

@@ -81,3 +82,3 @@ buf.fill(0)

var indexOf = function(block, num, offset, end) {
var indexOf = function (block, num, offset, end) {
for (; offset < end; offset++) {

@@ -89,15 +90,15 @@ if (block[offset] === num) return offset

var cksum = function(block) {
var cksum = function (block) {
var sum = 8 * 32
for (var i = 0; i < 148; i++) sum += block[i]
for (var i = 156; i < 512; i++) sum += block[i]
for (var i = 0; i < 148; i++) sum += block[i]
for (var j = 156; j < 512; j++) sum += block[j]
return sum
}
var encodeOct = function(val, n) {
var encodeOct = function (val, n) {
val = val.toString(8)
return ZEROS.slice(0, n-val.length)+val+' '
return ZEROS.slice(0, n - val.length) + val + ' '
}
var decodeOct = function(val, offset) {
var decodeOct = function (val, offset) {
// Older versions of tar can prefix with spaces

@@ -111,7 +112,7 @@ while (offset < val.length && val[offset] === 32) offset++

var decodeStr = function(val, offset, length) {
return val.slice(offset, indexOf(val, 0, offset, offset+length)).toString();
var decodeStr = function (val, offset, length) {
return val.slice(offset, indexOf(val, 0, offset, offset + length)).toString()
}
var addLength = function(str) {
var addLength = function (str) {
var len = Buffer.byteLength(str)

@@ -121,17 +122,17 @@ var digits = Math.floor(Math.log(len) / Math.log(10)) + 1

return (len+digits)+str
return (len + digits) + str
}
exports.decodeLongPath = function(buf) {
exports.decodeLongPath = function (buf) {
return decodeStr(buf, 0, buf.length)
}
exports.encodePax = function(opts) { // TODO: encode more stuff in pax
exports.encodePax = function (opts) { // TODO: encode more stuff in pax
var result = ''
if (opts.name) result += addLength(' path='+opts.name+'\n')
if (opts.linkname) result += addLength(' linkpath='+opts.linkname+'\n')
if (opts.name) result += addLength(' path=' + opts.name + '\n')
if (opts.linkname) result += addLength(' linkpath=' + opts.linkname + '\n')
return new Buffer(result)
}
exports.decodePax = function(buf) {
exports.decodePax = function (buf) {
var result = {}

@@ -142,10 +143,9 @@

while (i < buf.length && buf[i] !== 32) i++
var len = parseInt(buf.slice(0, i).toString())
var len = parseInt(buf.slice(0, i).toString(), 10)
if (!len) return result
var b = buf.slice(i+1, len-1).toString()
var b = buf.slice(i + 1, len - 1).toString()
var keyIndex = b.indexOf('=')
if (keyIndex === -1) return result
result[b.slice(0, keyIndex)] = b.slice(keyIndex+1)
result[b.slice(0, keyIndex)] = b.slice(keyIndex + 1)

@@ -158,3 +158,3 @@ buf = buf.slice(len)

exports.encode = function(opts) {
exports.encode = function (opts) {
var buf = alloc(512)

@@ -164,3 +164,3 @@ var name = opts.name

if (opts.typeflag === 5 && name[name.length-1] !== '/') name += '/'
if (opts.typeflag === 5 && name[name.length - 1] !== '/') name += '/'
if (Buffer.byteLength(name) !== name.length) return null // utf-8

@@ -172,3 +172,3 @@

prefix += prefix ? '/' + name.slice(0, i) : name.slice(0, i)
name = name.slice(i+1)
name = name.slice(i + 1)
}

@@ -180,3 +180,3 @@

buf.write(name)
buf.write(encodeOct(opts.mode & 07777, 6), 100)
buf.write(encodeOct(opts.mode & MASK, 6), 100)
buf.write(encodeOct(opts.uid, 6), 108)

@@ -204,3 +204,3 @@ buf.write(encodeOct(opts.gid, 6), 116)

exports.decode = function(buf) {
exports.decode = function (buf) {
var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET

@@ -221,3 +221,3 @@

if (buf[345]) name = decodeStr(buf, 345, 155)+'/'+name
if (buf[345]) name = decodeStr(buf, 345, 155) + '/' + name

@@ -229,7 +229,7 @@ // to support old tar versions that use trailing / to indicate dirs

//checksum is still initial value if header was null.
if (c === 8*32) return null
// checksum is still initial value if header was null.
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?")
// valid checksum
if (c !== decodeOct(buf, 148)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?')

@@ -236,0 +236,0 @@ return {

@@ -6,3 +6,2 @@ var constants = require('constants')

var Readable = require('readable-stream').Readable
var PassThrough = require('readable-stream').PassThrough
var Writable = require('readable-stream').Writable

@@ -13,2 +12,4 @@ var StringDecoder = require('string_decoder').StringDecoder

var DMODE = parseInt('755', 8)
var FMODE = parseInt('644', 8)

@@ -18,5 +19,5 @@ var END_OF_TAR = new Buffer(1024)

var noop = function() {}
var noop = function () {}
var overflow = function(self, size) {
var overflow = function (self, size) {
size &= 511

@@ -26,3 +27,3 @@ if (size) self.push(END_OF_TAR.slice(0, 512 - size))

function modeToType(mode) {
function modeToType (mode) {
switch (mode & constants.S_IFMT) {

@@ -39,3 +40,3 @@ case constants.S_IFBLK: return 'block-device'

var Sink = function(to) {
var Sink = function (to) {
Writable.call(this)

@@ -49,3 +50,3 @@ this.written = 0

Sink.prototype._write = function(data, enc, cb) {
Sink.prototype._write = function (data, enc, cb) {
this.written += data.length

@@ -56,3 +57,3 @@ if (this._to.push(data)) return cb()

Sink.prototype.destroy = function() {
Sink.prototype.destroy = function () {
if (this._destroyed) return

@@ -77,3 +78,3 @@ this._destroyed = true

LinkSink.prototype.destroy = function() {
LinkSink.prototype.destroy = function () {
if (this._destroyed) return

@@ -84,3 +85,3 @@ this._destroyed = true

var Void = function() {
var Void = function () {
Writable.call(this)

@@ -92,7 +93,7 @@ this._destroyed = false

Void.prototype._write = function(data, enc, cb) {
Void.prototype._write = function (data, enc, cb) {
cb(new Error('No body allowed for this entry'))
}
Void.prototype.destroy = function() {
Void.prototype.destroy = function () {
if (this._destroyed) return

@@ -103,3 +104,3 @@ this._destroyed = true

var Pack = function(opts) {
var Pack = function (opts) {
if (!(this instanceof Pack)) return new Pack(opts)

@@ -117,3 +118,3 @@ Readable.call(this, opts)

Pack.prototype.entry = function(header, buffer, callback) {
Pack.prototype.entry = function (header, buffer, callback) {
if (this._stream) throw new Error('already piping an entry')

@@ -131,7 +132,7 @@ if (this._finalized || this._destroyed) return

if (!header.size) header.size = 0
if (!header.type) header.type = modeToType(header.mode)
if (!header.mode) header.mode = header.type === 'directory' ? 0755 : 0644
if (!header.uid) header.uid = 0
if (!header.gid) header.gid = 0
if (!header.size) header.size = 0
if (!header.type) header.type = modeToType(header.mode)
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()

@@ -151,3 +152,3 @@

var linkSink = new LinkSink()
eos(linkSink, function(err) {
eos(linkSink, function (err) {
if (err) { // stream was closed

@@ -177,3 +178,3 @@ self.destroy()

eos(sink, function(err) {
eos(sink, function (err) {
self._stream = null

@@ -199,3 +200,3 @@

Pack.prototype.finalize = function() {
Pack.prototype.finalize = function () {
if (this._stream) {

@@ -212,3 +213,3 @@ this._finalizing = true

Pack.prototype.destroy = function(err) {
Pack.prototype.destroy = function (err) {
if (this._destroyed) return

@@ -222,3 +223,3 @@ this._destroyed = true

Pack.prototype._encode = function(header) {
Pack.prototype._encode = function (header) {
var buf = headers.encode(header)

@@ -229,3 +230,3 @@ if (buf) this.push(buf)

Pack.prototype._encodePax = function(header) {
Pack.prototype._encodePax = function (header) {
var paxHeader = headers.encodePax({

@@ -260,3 +261,3 @@ name: header.name,

Pack.prototype._read = function(n) {
Pack.prototype._read = function (n) {
var drain = this._drain

@@ -263,0 +264,0 @@ this._drain = noop

{
"name": "tar-stream",
"version": "1.3.0",
"version": "1.3.1",
"description": "tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.",

@@ -17,6 +17,7 @@ "author": "Mathias Buus <mathiasbuus@gmail.com>",

"concat-stream": "^1.4.6",
"standard": "^5.3.1",
"tape": "^3.0.3"
},
"scripts": {
"test": "tape test/*.js"
"test": "standard && tape test/*.js"
},

@@ -23,0 +24,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc