tar-iterator 0.2.4 → 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 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
+ });
@@ -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
- BaseIterator.prototype.end.call(this, err);
62
- if (this.extract) {
63
- this.extract = null;
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;
package/lib/nextEntry.js CHANGED
@@ -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.4",
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",
@@ -43,37 +43,39 @@
43
43
  "lib"
44
44
  ],
45
45
  "scripts": {
46
+ "build": "",
46
47
  "format": "prettier --write .",
47
48
  "lint": "eslint .",
48
- "prepublishOnly": "dtd \"npm run lint\" \"depcheck\"",
49
- "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"
50
52
  },
51
53
  "dependencies": {
52
54
  "end-of-stream": "^1.4.4",
53
55
  "extract-base-iterator": "^0.2.6",
54
- "fs-access-compat": "^1.0.2",
56
+ "fs-access-compat": "^1.0.3",
55
57
  "inherits": "^2.0.4",
56
- "just-extend": "^6.0.1",
58
+ "just-extend": "^6.1.1",
59
+ "lifecycle": "^1.0.4",
57
60
  "lodash.compact": "^3.0.1",
58
61
  "mkpath": "^1.0.0",
59
62
  "once": "^1.4.0",
60
- "queue-cb": "^1.1.6",
63
+ "queue-cb": "^1.1.7",
61
64
  "rimraf": "^2.7.1",
62
65
  "tar-stream-compat": "^2.1.5"
63
66
  },
64
67
  "devDependencies": {
65
- "@typescript-eslint/parser": "^5.30.0",
68
+ "@typescript-eslint/parser": "^5.33.0",
66
69
  "cr": "^0.1.0",
67
70
  "depcheck": "^1.4.3",
68
- "dis-dat": "^0.1.6",
69
- "eslint": "^8.18.0",
71
+ "eslint": "^8.21.0",
70
72
  "eslint-config-prettier": "^8.5.0",
71
73
  "eslint-config-standard": "^17.0.0",
72
74
  "eslint-plugin-import": "^2.26.0",
73
- "eslint-plugin-n": "^15.2.3",
75
+ "eslint-plugin-n": "^15.2.4",
74
76
  "eslint-plugin-promise": "^6.0.0",
75
77
  "fs-iterator": "^4.1.1",
76
- "fs-stats-spys": "^1.0.1",
78
+ "fs-stats-spys": "^1.0.2",
77
79
  "mocha-compat": "^3.5.5",
78
80
  "prettier": "^2.7.1",
79
81
  "unbzip2-stream": "^1.4.3"