1.2.22 • Published 9 months ago
extract-base-iterator v1.2.22
extract-base-iterator
Base iterator for extract iterators like tar-iterator and zip-iterator.
// asyncIterator
var assert = require('assert');
var BaseIterator = require('extract-base-iterator'));
// extend BaseIterator (see tests, tar-iterator, zip-iterator for examples)
(async function() {
var iterator = new YourIterator();
try {
const links = [];
for await (const entry of iterator) {
if (entry.type === 'link') links.unshift(entry);
else if (entry.type === 'symlink') links.push(entry);
else await entry.create(dest, options);
}
// create links after directories and files
for (const entry of links) await entry.create(dest, options);
} catch (err) {
}
iterator.destroy();
iterator = null;
})();
// Async / Await
var assert = require('assert');
var BaseIterator = require('extract-base-iterator'));
// extend BaseIterator (see tests, tar-iterator, zip-iterator for examples)
var iterator = new YourIterator();
// one by one
(async function() {
let iterator = new YourIterator();
try {
const links = [];
for await (const entry of iterator) {
if (entry.type === 'link') links.unshift(entry);
else if (entry.type === 'symlink') links.push(entry);
else await entry.create(dest, options);
}
// create links after directories and files
for (const entry of links) await entry.create(dest, options);
} catch (err) {
}
iterator.destroy();
iterator = null;
})();
// infinite concurrency
(async function() {
let iterator = new YourIterator();
try {
const links = [];
await iterator.forEach(
async function (entry) {
if (entry.type === 'link') links.unshift(entry);
else if (entry.type === 'symlink') links.push(entry);
else await entry.create(dest, options);
},
{ concurrency: Infinity }
);
// create links after directories and files
for (const entry of links) await entry.create(dest, options);
} catch (err) {
aseert.ok(!err);
}
iterator.destroy();
iterator = null;
})();
// Callbacks
var assert = require('assert');
var Queue = require('queue-cb');
var BaseIterator = require('extract-base-iterator'));
// extend BaseIterator (see tests, tar-iterator, zip-iterator for examples)
var iterator = new YourIterator();
// one by one
var links = [];
iterator.forEach(
function (entry, callback) {
if (entry.type === 'link') {
links.unshift(entry);
callback();
} else if (entry.type === 'symlink') {
links.push(entry);
callback();
} else entry.create(dest, options, callback);
},
{ callbacks: true, concurrency: 1 },
function (err) {
// create links after directories and files
var queue = new Queue();
for (var index = 0; index < links.length; index++) {
var entry = links[index];
queue.defer(entry.create.bind(entry, dest, options));
}
queue.await(callback);
iterator.destroy();
iterator = null;
}
);
1.2.17
9 months ago
1.2.18
9 months ago
1.2.19
9 months ago
1.2.20
9 months ago
1.2.21
9 months ago
1.2.22
9 months ago
1.2.16
9 months ago
1.2.15
9 months ago
1.2.13
9 months ago
1.2.14
9 months ago
1.2.12
9 months ago
1.2.11
9 months ago
1.2.0
10 months ago
1.2.8
10 months ago
1.2.7
10 months ago
1.2.6
10 months ago
1.2.5
10 months ago
1.1.6
10 months ago
1.2.4
10 months ago
1.2.3
10 months ago
1.2.2
10 months ago
1.2.1
10 months ago
1.2.9
10 months ago
1.2.10
10 months ago
1.1.5
10 months ago
1.1.4
10 months ago
1.1.3
11 months ago
1.1.2
11 months ago
1.1.1
11 months ago
1.1.0
11 months ago
1.0.1
2 years ago
1.0.0
2 years ago
0.3.0
2 years ago
0.4.1
2 years ago
0.4.0
2 years ago
0.2.6
3 years ago
0.2.5
5 years ago
0.2.3
5 years ago
0.2.4
5 years ago
0.2.1
5 years ago
0.2.2
5 years ago
0.2.0
5 years ago
0.1.9
5 years ago
0.1.8
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.4
5 years ago
0.1.3
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago