8000 feat: allow optional destination field for `asar extract-file` / `asar ef` by mmaietta · Pull Request #358 · electron/asar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: allow optional destination field for asar extract-file / asar ef #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mmaietta
Copy link
Contributor
@mmaietta mmaietta commented Mar 7, 2025

Adds an optional parameter to asar ef using [destination] optional arg syntax

Resolves 2 it.todo unit tests with the support of an output directory

@mmaietta mmaietta marked this pull request as ready for review March 7, 2025 19:29
@mmaietta mmaietta requested a review from a team as a code owner March 7, 2025 19:29
.command('extract-file <archive> <filename> [destination]')
.alias('ef')
.description(
'extract one file from archive. Optionally output to (already-existing) destination folder, otherwise cwd will be used',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do an fs.existsSync here to handle non existent paths more gracefully?

Copy link
Contributor Author
@mmaietta mmaietta Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great callout. Definitely can do! Okay with this error message to be thrown?

Related, what if we also throw an error if the destination file already exists? So that the user doesn't accidentally overwrite a file (like a sensitive/system resource if they enter a path with a space in it and don't wrap it in quotes lol?)
Alternatively, I add an optional --force arg to bypass the destination-file-already-exists error I'm proposing to also throw

  .action(function (archive, filename, destination) {
    const path = require('path');
    const fs = require('fs');

    const file = path.basename(filename);
    destination = destination?.trim()
    const out = destination ? path.join(destination, file) : file;
    if (!fs.existsSync(destination)) {
      throw new Error("destination directory does not exist, please create before attempting extraction")
    }
    if (fs.existsSync(out)) {
      throw new Error("destination file already exists")
    }
    fs.writeFileSync(out, asar.extractFile(archive, filename));
  });

Copy link
Contributor Author
@mmaietta mmaietta Mar 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the logic! Note: I had to asar.extractFile before fs.existsSync to retain previous behavior/unit test of "error thrown when file does not exist in asar"

Added additional unit test as well for the new throw Error logic path

@mmaietta mmaietta requested a review from erickzhao April 1, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0