Skip to content

Commit

Permalink
fix: optimize adding this.algorithm to algorithms list
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Apr 11, 2023
1 parent d90f674 commit 7fef846
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ class IntegrityStream extends MiniPass {

// options used for calculating stream. can't be changed.
if (opts?.algorithms) {
this.algorithms = Array.from(
new Set(opts.algorithms.concat(this.algorithm ? [this.algorithm] : []))
)
this.algorithms = [...opts.algorithms]
} else {
this.algorithms = [...DEFAULT_ALGORITHMS]

if (this.algorithm !== null && this.algorithm !== DEFAULT_ALGORITHMS[0]) {
this.algorithms.push(this.algorithm)
}
}
if (this.algorithm !== null && !this.algorithms.includes(this.algorithm)) {
this.algorithms.push(this.algorithm)
}

this.hashes = this.algorithms.map(crypto.createHash)
Expand Down

0 comments on commit 7fef846

Please sign in to comment.