Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e05727f

Browse files
committedOct 17, 2024·
more, prettier
1 parent 538774d commit e05727f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed
 

‎modules/decrypt-node/src/verify_stream.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,18 @@ export class VerifyStream extends PortableTransformWithType {
196196
if (chunk.length && tagLengthBytes > authTagBuffer.length) {
197197
const left = tagLengthBytes - authTagBuffer.length
198198
if (left > chunk.length) {
199-
state.authTagBuffer = Buffer.concat([authTagBuffer, chunk])
199+
// Buffer.concat can be expensive. If buffer is empty, just use the chunk.
200+
state.authTagBuffer =
201+
authTagBuffer.length > 0
202+
? Buffer.concat([authTagBuffer, chunk])
203+
: chunk
200204
return callback()
201205
} else {
202-
const finalAuthTagBuffer = Buffer.concat(
203-
[authTagBuffer, chunk],
204-
tagLengthBytes
205-
)
206+
// Buffer.concat can be expensive. If buffer is empty, just use the chunk.
207+
const finalAuthTagBuffer =
208+
authTagBuffer.length > 0
209+
? Buffer.concat([authTagBuffer, chunk], tagLengthBytes)
210+
: chunk.slice(0, tagLengthBytes)
206211
if (this._verify) {
207212
this._verify.update(finalAuthTagBuffer)
208213
}

0 commit comments

Comments
 (0)
Please sign in to comment.