Skip to content

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