Skip to content

Commit

Permalink
added alternative 7z driver
Browse files Browse the repository at this point in the history
  • Loading branch information
inlife committed Dec 12, 2024
1 parent 8bbcd82 commit 2adbd0f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
25 changes: 24 additions & 1 deletion packages/nexrender-action-decompress/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const AdmZip = require('adm-zip');
const { extractFull } = require('node-7z');

const decompress = (job, settings, asset, action) => {
if (asset.type === 'data') {
Expand Down Expand Up @@ -33,6 +34,28 @@ const decompress = (job, settings, asset, action) => {
zip.extractAllTo(job.workpath, action.overwrite || false);
}
break;

case 'zip-7z':
const promise = new Promise((resolve, reject) => {
const myStream = extractFull(asset.dest, job.workpath, {
$progress: true
})

myStream.on('progress', function (progress) {
settings.logger.log(`[action-decompress] Extracting ${progress.percent}%`);
})

myStream.on('end', function () {
resolve();
})

myStream.on('error', (err) => reject(err))
});

return promise;

default:
return Promise.resolve();
}

if (asset.decompressed) {
Expand All @@ -48,7 +71,7 @@ module.exports = (job, settings, action, type) => {
return Promise.reject("'action-decompress' module should be used only in 'prerender' section")
}

if (['zip'].indexOf(action.format) === -1) {
if (['zip', 'zip-7z'].indexOf(action.format) === -1) {
return Promise.reject(`'action-decompress' module doesn't support '${action.format}' format archives`)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/nexrender-action-decompress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"access": "public"
},
"dependencies": {
"adm-zip": "0.5.10"
"adm-zip": "0.5.10",
"node-7z": "^3.0.0"
}
}
37 changes: 37 additions & 0 deletions packages/nexrender-action-decompress/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,43 @@ describe('actions/decompress', function() {
.catch(done);
});

it('it should extract zip files with 7z', function(done) {
const job = {
workpath: workpath,
template: {
dest: path.join(workpath, 'template.zip'),
decompressed: 'template.aep',
},
assets: [
{
dest: path.join(workpath, 'asset.zip'),
decompressed: 'asset.jpg',
},
{
dest: path.join(workpath, 'non-archive.jpg'),
}
],
};

decompressAction(job, {}, { format: 'zip-7z' }, 'prerender')
.then(() => {
// ensure each file is extracted
assert(fs.existsSync(path.join(workpath, 'template.aep')));
assert(fs.existsSync(path.join(workpath, '(Footage)', 'test.jpg')));
assert(fs.existsSync(path.join(workpath, 'asset.jpg')));
assert(fs.existsSync(path.join(workpath, 'non-archive.jpg')));

// ensure each file has correct content
assert.strictEqual(fs.readFileSync(path.join(workpath, 'template.aep'), 'utf8'), 'hello there 1');
assert.strictEqual(fs.readFileSync(path.join(workpath, '(Footage)', 'test.jpg'), 'utf8'), 'hello there 2');
assert.strictEqual(fs.readFileSync(path.join(workpath, 'asset.jpg'), 'utf8'), 'hello there 3');
assert.strictEqual(fs.readFileSync(path.join(workpath, 'non-archive.jpg'), 'utf8'), 'hello there 4');

done();
})
.catch(done);
});

it('should update the dest values for each asset to reflect the extracted files', function(done) {
const job = {
workpath: workpath,
Expand Down

0 comments on commit 2adbd0f

Please sign in to comment.