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

tar-async

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tar-async - npm Package Compare versions

Comparing version 1.1.4 to 1.2.0

2

package.json

@@ -6,3 +6,3 @@ {

"keywords": ["tar", "untar", "asynchronous", "stream", "async", "chunk", "chunked"],
"version": "1.1.4",
"version": "1.2.0",
"repository": {

@@ -9,0 +9,0 @@ "type": "git",

@@ -30,2 +30,3 @@ (function () {

tape.emit('data', utils.clean(blockSize - (tape.written % blockSize)));
this.written += blockSize - (tape.written % blockSize);
});

@@ -46,12 +47,4 @@

Tar.prototype.append = function (filepath, input, opts, callback) {
var data,
checksum,
mode,
mtime,
uid,
gid,
size,
tape = this,
extraBytes,
Tar.prototype.createHeader = function (data) {
var checksum,
i,

@@ -61,58 +54,2 @@ length,

if (typeof opts === 'function') {
callback = opts;
opts = {};
}
if (typeof callback !== 'function') {
callback = function (err, data) {
if (err) {
throw err;
}
return data;
};
}
if (this.processing || queue.length) {
queue.push({
filepath: filepath,
input: input,
opts: opts,
cb: callback
});
return;
}
opts = opts || {};
mode = typeof opts.mode === 'number' ? opts.mode : parseInt('777', 8) & 0xfff;
mtime = typeof opts.mtime === 'number' ? opts.mtime : parseInt(+new Date() / 1000);
uid = typeof opts.uid === 'number' ? opts.uid : 0;
gid = typeof opts.gid === 'number' ? opts.gid : 0;
size = typeof opts.size === 'number' ? opts.size : input.length;
// if you give me a stream, you must tell me how big it is
// since the header comes first, the only other solution is to
// cache the entire file before writing it out to a stream,
// which completely invalidates the purpose of a stream
if (input instanceof Stream && (typeof size !== 'number' || size < 0)) {
console.log('Error:', size);
return callback(new Error('Streams must supply the total size of the stream.'));
}
data = {
filename: this.consolidate ? path.basename(filepath) : filepath,
mode: utils.pad(mode, 7),
uid: utils.pad(uid, 7),
gid: utils.pad(gid, 7),
size: utils.pad(size, 11),
mtime: utils.pad(mtime, 11),
checksum: ' ',
type: '0', // just a file
ustar: 'ustar ',
owner: '',
group: ''
};
if (this.normalize && !this.consolidate) {

@@ -144,5 +81,12 @@ data.filename = path.normalize(data.filename);

return headerBuf;
};
Tar.prototype.writeData = function (callback, header, input, size) {
var extraBytes,
tape = this;
// and write it out to the stream
this.emit('data', headerBuf);
this.written += headerBuf.length;
this.emit('data', header);
this.written += header.length;

@@ -155,3 +99,3 @@ // if it's a string/Buffer, we can just write it out to the stream

extraBytes = recordSize - (size % recordSize || recordSize);
this.emit('data', utils.clean(recordSize - (size % recordSize)));
this.emit('data', utils.clean(extraBytes));
this.written += extraBytes;

@@ -180,2 +124,6 @@

if (typeof job.input === 'object' && typeof job.input.resume === 'function') {
job.input.resume();
}
tape.append(job.filepath, job.input, job.opts, job.cb);

@@ -189,4 +137,91 @@ });

};
Tar.prototype.append = function (filepath, input, opts, callback) {
var data,
mode,
mtime,
uid,
gid,
size,
tape = this;
if (typeof opts === 'function') {
callback = opts;
opts = {};
}
if (typeof callback !== 'function') {
callback = function (err, data) {
if (err) {
throw err;
}
return data;
};
}
if (this.processing || queue.length) {
if (typeof input === 'object' && typeof input.pause === 'function') {
input.pause();
}
queue.push({
filepath: filepath,
input: input,
opts: opts,
cb: callback
});
return;
}
opts = opts || {};
mode = typeof opts.mode === 'number' ? opts.mode : parseInt('777', 8) & 0xfff;
mtime = typeof opts.mtime === 'number' ? opts.mtime : parseInt(+new Date() / 1000);
uid = typeof opts.uid === 'number' ? opts.uid : 0;
gid = typeof opts.gid === 'number' ? opts.gid : 0;
size = typeof opts.size === 'number' ? opts.size : input.length;
// if you give me a stream, you must tell me how big it is
// since the header comes first, the only other solution is to
// cache the entire file before writing it out to a stream,
// which completely invalidates the purpose of a stream
if (input instanceof Stream && (typeof size !== 'number' || size < 0)) {
if (opts.allowPipe) {
size = -1;
} else {
console.error('Error:', size);
return callback(new Error('Streams must supply the total size of the stream if allowPipe is not set.'));
}
}
data = {
filename: this.consolidate ? path.basename(filepath) : filepath,
mode: utils.pad(mode, 7),
uid: utils.pad(uid, 7),
gid: utils.pad(gid, 7),
size: utils.pad(size, 11),
mtime: utils.pad(mtime, 11),
checksum: ' ',
type: '0', // just a file
ustar: 'ustar ',
owner: '',
group: ''
};
if (size === -1 && opts.allowPipe) {
this.processing = true;
utils.readAll(function (err, buf) {
tape.processing = false;
size = buf.length;
data.size = utils.pad(size, 11);
tape.writeData(callback, tape.createHeader(data), buf, size);
}, input);
} else {
this.writeData(callback, this.createHeader(data), input, size);
}
};
module.exports = Tar;
}());

@@ -16,5 +16,28 @@ (function () {

}
function readAll(cb, stream) {
var bufs = [],
size = 0;
stream.on('error', cb);
stream.on('data', function (data) {
bufs.push(data);
size += data.length;
});
stream.on('end', function () {
var buf = new Buffer(size),
offset = 0;
bufs.forEach(function (data) {
data.copy(buf, offset);
offset += data.length;
});
cb(null, buf);
});
}
module.exports.clean = clean;
module.exports.pad = pad;
module.exports.readAll = readAll;
}());
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