0

I need to read a content of a password-protected archive (zip is preferred) to a node-js app, without writing the protected content to a file

In addition, the app is cross-platform so solution such this doesn't help

I looked also here but there is no code in the answer

o.z
  • 1,086
  • 14
  • 22

2 Answers2

2

The only library I can find that supports encryption is: https://github.com/rf00/minizip-asm.js

Unfortunately, it isn't well maintained.

user189271
  • 178
  • 1
  • 7
0

This solution will read the file buffer which you can get from base64 or by reading the zip file, after that unzipping and opening the password-protected file is done in-memory. I hope this helps -

const unzipper = require("unzipper");

const unzipAndUnlockZipFileFromBuffer = async (zippedFileBase64, password) => {
  try {
    const zipBuffer = Buffer.from(zippedFileBase64, "base64"); // Change base64 to buffer
    const zipDirectory = await unzipper.Open.buffer(zipBuffer); // unzip a buffered file
    const file = zipDirectory.files[0]; // find the file you want

    // if you want to find a specific file by path
    // const file = zipDirectory.files.find((f) => f.path === "filename");

    const extracted = await file.buffer(password); // unlock the file with the password

    console.log(extracted.toString()); // file content
  } catch (e) {
    console.log(e);
  }
};

const zippedFileBase64 = "{{BASE64}}";
const password = "1234";
unzipAndUnlockZipFileFromBuffer(zippedFileBase64, password);
Nakul Sharma
  • 419
  • 1
  • 4
  • 13