tar-iterator 0.2.2 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/FileEntry.js +33 -1
- package/lib/Lock.js +14 -0
- package/lib/TarIterator.js +12 -4
- package/{index.js → lib/index.js} +2 -2
- package/lib/nextEntry.js +2 -2
- package/package.json +25 -22
package/lib/FileEntry.js
CHANGED
|
@@ -5,13 +5,40 @@ var eos = require('end-of-stream');
|
|
|
5
5
|
|
|
6
6
|
var waitForAccess = require('./waitForAccess');
|
|
7
7
|
|
|
8
|
-
function FileEntry(attributes, stream) {
|
|
8
|
+
function FileEntry(attributes, stream, lock) {
|
|
9
9
|
BaseIterator.FileEntry.call(this, attributes);
|
|
10
10
|
this.stream = stream;
|
|
11
|
+
this.lock = lock;
|
|
12
|
+
this.lock.retain();
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
inherits(FileEntry, BaseIterator.FileEntry);
|
|
14
16
|
|
|
17
|
+
FileEntry.prototype.create = function create(dest, options, callback) {
|
|
18
|
+
if (typeof options === 'function') {
|
|
19
|
+
callback = options;
|
|
20
|
+
options = null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var self = this;
|
|
24
|
+
if (typeof callback === 'function') {
|
|
25
|
+
options = options || {};
|
|
26
|
+
return BaseIterator.FileEntry.prototype.create.call(this, dest, options, function createCallback(err) {
|
|
27
|
+
callback(err);
|
|
28
|
+
if (self.lock) {
|
|
29
|
+
self.lock.release();
|
|
30
|
+
self.lock = null;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return new Promise(function createPromise(resolve, reject) {
|
|
36
|
+
self.create(dest, options, function createCallback(err, done) {
|
|
37
|
+
err ? reject(err) : resolve(done);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
15
42
|
FileEntry.prototype._writeFile = function _writeFile(fullPath, options, callback) {
|
|
16
43
|
if (!this.stream) return callback(new Error('Zip FileEntry missing stream. Check for calling create multiple times'));
|
|
17
44
|
|
|
@@ -26,8 +53,13 @@ FileEntry.prototype._writeFile = function _writeFile(fullPath, options, callback
|
|
|
26
53
|
FileEntry.prototype.destroy = function destroy() {
|
|
27
54
|
BaseIterator.FileEntry.prototype.destroy.call(this);
|
|
28
55
|
if (this.stream) {
|
|
56
|
+
this.stream.resume(); // drain stream
|
|
29
57
|
this.stream = null;
|
|
30
58
|
}
|
|
59
|
+
if (this.lock) {
|
|
60
|
+
this.lock.release();
|
|
61
|
+
this.lock = null;
|
|
62
|
+
}
|
|
31
63
|
};
|
|
32
64
|
|
|
33
65
|
module.exports = FileEntry;
|
package/lib/Lock.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var LC = require('lifecycle');
|
|
2
|
+
var BaseIterator = require('extract-base-iterator');
|
|
3
|
+
|
|
4
|
+
module.exports = LC.RefCountable.extend({
|
|
5
|
+
constructor: function () {
|
|
6
|
+
LC.RefCountable.prototype.constructor.apply(this, arguments);
|
|
7
|
+
},
|
|
8
|
+
__destroy: function () {
|
|
9
|
+
if (this.iterator) {
|
|
10
|
+
BaseIterator.prototype.end.call(this.iterator, this.err || null);
|
|
11
|
+
this.iterator = null;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
});
|
package/lib/TarIterator.js
CHANGED
|
@@ -7,12 +7,16 @@ var BaseIterator = require('extract-base-iterator');
|
|
|
7
7
|
|
|
8
8
|
var nextEntry = require('./nextEntry');
|
|
9
9
|
var fifoRemove = require('./fifoRemove');
|
|
10
|
+
var Lock = require('./Lock');
|
|
10
11
|
|
|
11
12
|
function TarIterator(source, options) {
|
|
12
13
|
if (!(this instanceof TarIterator)) return new TarIterator(source, options);
|
|
13
14
|
BaseIterator.call(this, options);
|
|
14
15
|
|
|
15
16
|
var self = this;
|
|
17
|
+
this.lock = new Lock();
|
|
18
|
+
this.lock.iterator = this;
|
|
19
|
+
|
|
16
20
|
var queue = Queue(1);
|
|
17
21
|
var cancelled = false;
|
|
18
22
|
function setup() {
|
|
@@ -50,7 +54,7 @@ function TarIterator(source, options) {
|
|
|
50
54
|
// start processing
|
|
51
55
|
queue.await(function (err) {
|
|
52
56
|
fifoRemove(self.processing, setup);
|
|
53
|
-
if (self.done || cancelled) return;
|
|
57
|
+
if (self.done || cancelled) return; // done
|
|
54
58
|
err ? self.end(err) : self.push(nextEntry.bind(null, null));
|
|
55
59
|
});
|
|
56
60
|
}
|
|
@@ -58,10 +62,14 @@ function TarIterator(source, options) {
|
|
|
58
62
|
inherits(TarIterator, BaseIterator);
|
|
59
63
|
|
|
60
64
|
TarIterator.prototype.end = function end(err) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.
|
|
65
|
+
if (this.lock) {
|
|
66
|
+
this.lock.err = err;
|
|
67
|
+
this.lock.release();
|
|
68
|
+
this.lock = null;
|
|
69
|
+
} else {
|
|
70
|
+
BaseIterator.prototype.end.call(this, err); // call in lock release so end is properly handled
|
|
64
71
|
}
|
|
72
|
+
this.extract = null;
|
|
65
73
|
};
|
|
66
74
|
|
|
67
75
|
module.exports = TarIterator;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var BaseIterator = require('extract-base-iterator');
|
|
2
2
|
|
|
3
|
-
module.exports = require('./
|
|
3
|
+
module.exports = require('./TarIterator');
|
|
4
4
|
module.exports.DirectoryEntry = BaseIterator.DirectoryEntry;
|
|
5
|
-
module.exports.FileEntry = require('./
|
|
5
|
+
module.exports.FileEntry = require('./FileEntry');
|
|
6
6
|
module.exports.LinkEntry = BaseIterator.LinkEntry;
|
|
7
7
|
module.exports.SymbolicLinkEntry = BaseIterator.SymbolicLinkEntry;
|
package/lib/nextEntry.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var once = require('once');
|
|
2
2
|
var path = require('path');
|
|
3
3
|
var compact = require('lodash.compact');
|
|
4
|
-
var assign = require('
|
|
4
|
+
var assign = require('just-extend');
|
|
5
5
|
|
|
6
6
|
var BaseIterator = require('extract-base-iterator');
|
|
7
7
|
var DirectoryEntry = BaseIterator.DirectoryEntry;
|
|
@@ -48,7 +48,7 @@ function nextEntry(next, iterator, callback) {
|
|
|
48
48
|
attributes.linkpath = header.linkname;
|
|
49
49
|
return callback(null, new LinkEntry(attributes), next);
|
|
50
50
|
case 'file':
|
|
51
|
-
return callback(null, new FileEntry(attributes, stream), next);
|
|
51
|
+
return callback(null, new FileEntry(attributes, stream, iterator.lock), next);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
stream.resume(); // drain stream
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tar-iterator",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Extract contents from tar archive type using an iterator API using streams or paths. Use stream interface and pipe transforms to add decompression algorithms",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"extract",
|
|
@@ -38,43 +38,46 @@
|
|
|
38
38
|
},
|
|
39
39
|
"license": "MIT",
|
|
40
40
|
"author": "Kevin Malakoff <kmalakoff@gmail.com> (https://github.com/kmalakoff)",
|
|
41
|
-
"main": "index.js",
|
|
41
|
+
"main": "lib/index.js",
|
|
42
|
+
"files": [
|
|
43
|
+
"lib"
|
|
44
|
+
],
|
|
42
45
|
"scripts": {
|
|
46
|
+
"build": "",
|
|
43
47
|
"format": "prettier --write .",
|
|
44
48
|
"lint": "eslint .",
|
|
45
|
-
"prepublishOnly": "
|
|
46
|
-
"test": "mocha-compat test/spec/**/*.test.js --no-timeouts"
|
|
49
|
+
"prepublishOnly": "npm run lint && depcheck",
|
|
50
|
+
"test": "mocha-compat test/spec/**/*.test.js --no-timeouts",
|
|
51
|
+
"test:engines": "nvu engines npm test"
|
|
47
52
|
},
|
|
48
53
|
"dependencies": {
|
|
49
54
|
"end-of-stream": "^1.4.4",
|
|
50
|
-
"extract-base-iterator": "^0.2.
|
|
51
|
-
"fs-access-compat": "^1.0.
|
|
52
|
-
"graceful-fs": "^4.2.8",
|
|
55
|
+
"extract-base-iterator": "^0.2.6",
|
|
56
|
+
"fs-access-compat": "^1.0.3",
|
|
53
57
|
"inherits": "^2.0.4",
|
|
58
|
+
"just-extend": "^6.1.1",
|
|
59
|
+
"lifecycle": "^1.0.4",
|
|
54
60
|
"lodash.compact": "^3.0.1",
|
|
55
61
|
"mkpath": "^1.0.0",
|
|
56
|
-
"object-assign": "^4.1.1",
|
|
57
62
|
"once": "^1.4.0",
|
|
58
|
-
"queue-cb": "^1.1.
|
|
63
|
+
"queue-cb": "^1.1.7",
|
|
59
64
|
"rimraf": "^2.7.1",
|
|
60
65
|
"tar-stream-compat": "^2.1.5"
|
|
61
66
|
},
|
|
62
67
|
"devDependencies": {
|
|
63
|
-
"
|
|
68
|
+
"@typescript-eslint/parser": "^5.33.0",
|
|
64
69
|
"cr": "^0.1.0",
|
|
65
|
-
"depcheck": "^1.4.
|
|
66
|
-
"
|
|
67
|
-
"eslint": "^
|
|
68
|
-
"eslint-config-
|
|
69
|
-
"eslint-
|
|
70
|
-
"eslint-plugin-
|
|
71
|
-
"eslint-plugin-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"fs-iterator": "^4.1.0",
|
|
75
|
-
"fs-stats-spys": "^1.0.1",
|
|
70
|
+
"depcheck": "^1.4.3",
|
|
71
|
+
"eslint": "^8.21.0",
|
|
72
|
+
"eslint-config-prettier": "^8.5.0",
|
|
73
|
+
"eslint-config-standard": "^17.0.0",
|
|
74
|
+
"eslint-plugin-import": "^2.26.0",
|
|
75
|
+
"eslint-plugin-n": "^15.2.4",
|
|
76
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
77
|
+
"fs-iterator": "^4.1.1",
|
|
78
|
+
"fs-stats-spys": "^1.0.2",
|
|
76
79
|
"mocha-compat": "^3.5.5",
|
|
77
|
-
"prettier": "^2.
|
|
80
|
+
"prettier": "^2.7.1",
|
|
78
81
|
"unbzip2-stream": "^1.4.3"
|
|
79
82
|
},
|
|
80
83
|
"engines": {
|