From 83b5e2f818ef514bccba11088c80e98d9f4c7a71 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Wed, 8 Oct 2025 16:50:12 -0400 Subject: [PATCH] Prevent making an unnecessary copy when encoding bytes. --- CHANGELOG.md | 5 +++++ lib/util.js | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f512718..a1ef17b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # @digitalbazaar/http-digest-header Changelog +## 2.2.1 - 2025-10-dd + +### Fixed +- Prevent making an unnecessary copy when encoding bytes. + ## 2.2.0 - 2025-10-08 ### Changed diff --git a/lib/util.js b/lib/util.js index c524a16..fb43b54 100644 --- a/lib/util.js +++ b/lib/util.js @@ -2,9 +2,11 @@ * Copyright (c) 2021-2025 Digital Bazaar, Inc. All rights reserved. */ export function base64Encode(bytes) { - return Buffer.from(bytes).toString('base64'); + return Buffer.from(bytes.buffer, bytes.offset, bytes.length) + .toString('base64'); } export function base64urlEncode(bytes) { - return Buffer.from(bytes).toString('base64url'); + return Buffer.from(bytes.buffer, bytes.offset, bytes.length) + .toString('base64url'); }