From df155733dd25033f90d11868ca208a375e753fb2 Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Fri, 14 Feb 2025 08:14:18 -0700 Subject: [PATCH] always use `Buffer.byteLength` to determine length there is no need to check the entity type because `Buffer.byteLength` works correctly for both `String` and `Buffer` `utf8` is the default encoding when entity is a `String` this change also make the module compatible with `TypedArray` entities see: https://nodejs.org/api/buffer.html#static-method-bufferbytelengthstring-encoding --- index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.js b/index.js index 2a585c9..5333ada 100644 --- a/index.js +++ b/index.js @@ -50,9 +50,7 @@ function entitytag (entity) { .substring(0, 27) // compute length of entity - var len = typeof entity === 'string' - ? Buffer.byteLength(entity, 'utf8') - : entity.length + var len = Buffer.byteLength(entity) return '"' + len.toString(16) + '-' + hash + '"' }