Does anyone know how I can unzip a file with javascript?

Hello, I have created an express server and a bundled react app for my brightsign player. In addition I have each of these running via my autorun.brs. I am making a request from react to the express server to download a zip file from an external endpoint and unzip it. I am able to successfully download the file, but then I am getting the following error:

[ 63.088] finished downloading 
[ 63.260] start unzip
[ 63.573] internal/fs/utils.js:314
[ 63.573] throw err;
[ 63.573] ^
[ 63.573]
[ 63.573] Error: EPERM: operation not permitted, chmod '/storage/sd/media/slides/133444725423.png'
[ 63.573] at Object.chmodSync (fs.js:1320:3)
[ 63.573] at Utils.writeFileTo (/storage/sd/node_modules/adm-zip/util/utils.js:89:13)
[ 63.573] at /storage/sd/node_modules/adm-zip/adm-zip.js:616:27
[ 63.573] at Array.forEach (<anonymous>)
[ 63.573] at Object.extractAllTo (/storage/sd/node_modules/adm-zip/adm-zip.js:604:26)
[ 63.573] at WriteStream.<anonymous> (/storage/sd/app.js:66:11)
[ 63.573] at WriteStream.emit (events.js:400:28)
[ 63.573] at finish (internal/streams/writable.js:657:10)
[ 63.573] at finishMaybe (internal/streams/writable.js:644:9)
[ 63.573] at internal/streams/writable.js:617:7 {
[ 63.573] errno: -1,
[ 63.573] syscall: 'chmod',
[ 63.573] code: 'EPERM',

I do not believe this linux distribution has the chmod command. My main question is... does it have chmod and is there a way I can give this script permission to run it? or more likely, does anyone know of a js lib that can unzip archives without calling chmod?


  • 0
  • 0
    Brandon Stryker

    @Mkramer thank you for trying to help, however, though they share the word java, java and javascript are completely languages and javascript cannot use java libraries as far as I know. I was able to use a library called decompress. This is still erroring on the attempt to call utime, but this is not integral to the functionality and seems to only affect the metadata for a file/directory (time created/edited). Here is the code:

    const decompress = require("decompress");

    const zipFile = path.join(storagePath, "media", "archive.zip");
    constoutputDir = path.join(storagePath, "media");

    console.log("$$$ Making download request $$$");
    let fileUrl = "some url";
    let headers = {"some key": "some value"};
    .get({ headers: headers, url: fileUrl })
    .on("error", function (error) {
    .on("finish", async () => {
    console.log("$$$ finished downloading $$$");
    console.log("$$$ start unzip $$$");
    awaitdecompress("/storage/sd/media/archive.zip", "/storage/sd/media")
    .then(() => console.log("$$$ finished unzipping $$$"))
    .catch((err) => console.log(err));
    console.log("!!! past decompress function !!!");
    while (true) {
    awaitnewPromise((res) =>setTimeout(res, 5000));
    if (fs.existsSync(path.join(storagePath, "media", "index.html"))) {
    console.log("$$$ it seems files were extracted successfully $$$");
    res.json({ successful:true });
  • 0
  • 0
    Brandon Stryker

    Yes I did, that is where I found the decompress library. The code sample I included above works fine. I believe most of these unzipper libraries are going to try to call some system function to change file permissions or do something. Brightsign players have a very lightweight version of linux with no way (as far as I can tell) to install additional linux utilities or functions. I'm sure many of the libraries will error in some way at some point. The one I have chose unzips the archive before it errors, which is good enough for me. It unzips, I catch error and do nothing about it, code continues on its merry way

  • 0

    You might submit a ticket asking BrightSign if you can load additional utilities or functions - just to see what the reply is.  :-)

  • 0
    Brandon Stryker

    yeahhhh I've considered it. I don't want to start messing around with the OS too much. Thank you for all your helpful suggestions though

Please sign in to leave a comment.