Skip to content

Should not remove props from options passed to init #146

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 1 commit into
base: master
Choose a base branch
from

Conversation

kroleg
Copy link

@kroleg kroleg commented Apr 4, 2025

My use case is like this: I need to re-init on scanning in case previously init failed. I am forced to use init like new NodeClam().init({ ...this.settings }) to preserve my settings props.
Also i think it's generally not recommended to modify args passed to a function. There is even a eslint rule for this: https://eslint.org/docs/latest/rules/no-param-reassign

export class FileScan {
  settings: NodeClam.Options;
  clam: Promise<NodeClam>;

  constructor() {
    const { host, port, debugMode } = config.clamscan;
    this.settings = {
      clamdscan: { host, port },
      preference: 'clamdscan',
    };

    // current version of NodeClam removes the clamdscan property from the options object, pass obj clone to avoid it
    this.clam = new NodeClam().init({ ...this.settings });
    // ...
  }


  async isFileClean(filePath: string) {
    let clamscan: NodeClam;
    // if clamscan failed to initialize, awaiting this.clamscan will throw an error
    // so we need to catch the error and try to reinitialize
    try {
      clamscan = await this.clam;
    } catch (err) {
      // current version of NodeClam removes the clamdscan property from the options object, pass obj clone to avoid it
      this.clam = new NodeClam().init({ ...this.settings });
      clamscan = await this.clam;
    }
    const { isInfected } = await clamscan.isInfected(filePath);
  }

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.

1 participant