File tree 1 file changed +10
-5
lines changed 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -196,13 +196,18 @@ export class VerifyStream extends PortableTransformWithType {
196
196
if ( chunk . length && tagLengthBytes > authTagBuffer . length ) {
197
197
const left = tagLengthBytes - authTagBuffer . length
198
198
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
200
204
return callback ( )
201
205
} 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 )
206
211
if ( this . _verify ) {
207
212
this . _verify . update ( finalAuthTagBuffer )
208
213
}
You can’t perform that action at this time.
0 commit comments