Skip to content

Commit a8f7168

Browse files
authored
Merge pull request #457 from Santa77/master
Extraction of password protected zip entries
2 parents 54c3817 + 7b6ed9d commit a8f7168

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ var AdmZip = require("adm-zip");
2929

3030
// reading archives
3131
var zip = new AdmZip("./my_file.zip");
32-
var zipEntries = zip.getEntries(); // an array of ZipEntry records
32+
var password = "1234567890";
33+
var zipEntries = zip.getEntries(); // an array of ZipEntry records - add password parameter if entries are password protected
3334

3435
zipEntries.forEach(function (zipEntry) {
3536
console.log(zipEntry.toString()); // outputs zip entries information

adm-zip.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,8 @@ module.exports = function (/**String*/ input, /** object */ options) {
471471
*
472472
* @return Array
473473
*/
474-
getEntries: function () {
474+
getEntries: function (/**String*/ password) {
475+
_zip.password=password;
475476
return _zip ? _zip.entries : [];
476477
},
477478

@@ -548,7 +549,7 @@ module.exports = function (/**String*/ input, /** object */ options) {
548549
return true;
549550
}
550551

551-
var content = item.getData();
552+
var content = item.getData(_zip.password);
552553
if (!content) throw new Error(Utils.Errors.CANT_EXTRACT_FILE);
553554

554555
if (filetools.fs.existsSync(target) && !overwrite) {

zipFile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = function (/*Buffer|null*/ inBuffer, /** object */ options) {
88
_comment = Buffer.alloc(0),
99
mainHeader = new Headers.MainHeader(),
1010
loadedEntries = false;
11+
var password = null;
1112

1213
// assign options
1314
const opts = Object.assign(Object.create(null), options);

0 commit comments

Comments
 (0)