Skip to content

Commit

Permalink
Merge pull request #457 from Santa77/master
Browse files Browse the repository at this point in the history
Extraction of password protected zip entries
  • Loading branch information
cthackers committed Mar 13, 2024
2 parents 54c3817 + 7b6ed9d commit a8f7168
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ var AdmZip = require("adm-zip");

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

zipEntries.forEach(function (zipEntry) {
console.log(zipEntry.toString()); // outputs zip entries information
Expand Down
5 changes: 3 additions & 2 deletions adm-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ module.exports = function (/**String*/ input, /** object */ options) {
*
* @return Array
*/
getEntries: function () {
getEntries: function (/**String*/ password) {
_zip.password=password;
return _zip ? _zip.entries : [];
},

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

var content = item.getData();
var content = item.getData(_zip.password);
if (!content) throw new Error(Utils.Errors.CANT_EXTRACT_FILE);

if (filetools.fs.existsSync(target) && !overwrite) {
Expand Down
1 change: 1 addition & 0 deletions zipFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = function (/*Buffer|null*/ inBuffer, /** object */ options) {
_comment = Buffer.alloc(0),
mainHeader = new Headers.MainHeader(),
loadedEntries = false;
var password = null;

// assign options
const opts = Object.assign(Object.create(null), options);
Expand Down

0 comments on commit a8f7168

Please sign in to comment.