tar-iterator 3.3.10 → 3.3.11

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.
Files changed (2) hide show
  1. package/README.md +18 -124
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,143 +1,37 @@
1
- ## tar-iterator
1
+ # tar-iterator
2
2
 
3
- Extract contents from tar archive type using an iterator API using streams or paths. Use stream interface and pipe transforms to add decompression algorithms.
3
+ Read entries from a tar archive through an iterator. Give it a file path or a readable stream. Use a decompression transform before the iterator for compressed tar input.
4
4
 
5
- // asyncIterator
6
-
7
- ```js
8
- var assert = require('assert');
9
- var fs = require('fs');
10
- var TarIterator = require('tar-iterator');
11
-
12
-
13
- (async function() {
14
- let iterator = new TarIterator('/path/to/archive');
15
-
16
- try {
17
- const links = [];
18
- for await (const entry of iterator) {
19
- if (entry.type === 'link') links.unshift(entry);
20
- else if (entry.type === 'symlink') links.push(entry);
21
- else await entry.create(dest, options);
22
- }
23
-
24
- // create links after directories and files
25
- for (const entry of links) await entry.create(dest, options);
26
- } catch (err) {
27
- }
28
-
29
- iterator.destroy();
30
- iterator = null;
31
- })();
32
-
33
- (async function() {
34
- let iterator = new TarIterator(fs.createReadStream('/path/to/archive'));
35
-
36
- try {
37
- const links = [];
38
- for await (const entry of iterator) {
39
- if (entry.type === 'link') links.unshift(entry);
40
- else if (entry.type === 'symlink') links.push(entry);
41
- else await entry.create(dest, options);
42
- }
43
-
44
- // create links after directories and files
45
- for (const entry of links) await entry.create(dest, options);
46
- } catch (err) {
47
- }
48
-
49
- iterator.destroy();
50
- iterator = null;
51
- })();
5
+ ```bash
6
+ npm install tar-iterator
52
7
  ```
53
8
 
54
- // Async / Await
9
+ ## Read entries
55
10
 
56
11
  ```js
57
- var assert = require('assert');
58
12
  var TarIterator = require('tar-iterator');
59
13
 
60
- // one by one
61
- (async function() {
62
- let iterator = new TarIterator('/path/to/archive');
14
+ (async function () {
15
+ var iterator = new TarIterator('/path/to/archive.tar');
63
16
 
64
17
  try {
65
- const links = [];
66
- for await (const entry of iterator) {
67
- if (entry.type === 'link') links.unshift(entry);
68
- else if (entry.type === 'symlink') links.push(entry);
69
- else await entry.create(dest, options);
70
- }
71
-
72
- // create links after directories and files
73
- for (const entry of links) await entry.create(dest, options);
74
- } catch (err) {
18
+ for await (var entry of iterator) {
19
+ console.log(entry.type, entry.path);
75
20
  }
76
-
77
- iterator.destroy();
78
- iterator = null;
79
- })();
80
-
81
- // infinite concurrency
82
- (async function() {
83
- let iterator = new TarIterator('/path/to/archive');
84
-
85
- try {
86
- const links = [];
87
- await iterator.forEach(
88
- async function (entry) {
89
- if (entry.type === 'link') links.unshift(entry);
90
- else if (entry.type === 'symlink') links.push(entry);
91
- else await entry.create(dest, options);
92
- },
93
- { concurrency: Infinity }
94
- );
95
-
96
- // create links after directories and files
97
- for (const entry of links) await entry.create(dest, options);
98
- } catch (err) {
99
- aseert.ok(!err);
21
+ } finally {
22
+ iterator.destroy();
100
23
  }
101
-
102
- iterator.destroy();
103
- iterator = null;
104
24
  })();
105
25
  ```
106
26
 
107
- // Callbacks
27
+ Each entry has a `type` and a `create(destination[, options])` method. Directory, file, hard-link, and symbolic-link entries can be created after iteration. Create links after files and directories when extracting an archive.
28
+
29
+ To read from a stream, pass a readable stream instead of the path:
108
30
 
109
31
  ```js
110
- var assert = require('assert');
111
- var Queue = require('queue-cb');
32
+ var fs = require('fs');
112
33
  var TarIterator = require('tar-iterator');
113
-
114
- var iterator = new TarIterator('/path/to/archive');
115
-
116
- // one by one
117
- var links = [];
118
- iterator.forEach(
119
- function (entry, callback) {
120
- if (entry.type === 'link') {
121
- links.unshift(entry);
122
- callback();
123
- } else if (entry.type === 'symlink') {
124
- links.push(entry);
125
- callback();
126
- } else entry.create(dest, options, callback);
127
- },
128
- { callbacks: true, concurrency: 1 },
129
- function (err) {
130
-
131
- // create links after directories and files
132
- var queue = new Queue();
133
- for (var index = 0; index < links.length; index++) {
134
- var entry = links[index];
135
- queue.defer(entry.create.bind(entry, dest, options));
136
- }
137
- queue.await(callback);
138
-
139
- iterator.destroy();
140
- iterator = null;
141
- }
142
- );
34
+ var iterator = new TarIterator(fs.createReadStream('/path/to/archive.tar'));
143
35
  ```
36
+
37
+ The package also exports `TarErrorCode`, `TarCodedError`, `FileEntry`, and extraction types.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tar-iterator",
3
- "version": "3.3.10",
3
+ "version": "3.3.11",
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",