Skip to content

Commit 7e70174

Browse files
committed
handle Uint8Array case
1 parent 1019f5e commit 7e70174

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/mongo_logger.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,12 @@ export function stringifyWithMaxLen(
486486
currentLength += value ? 4 : 5;
487487
break;
488488
case 'object':
489-
if ('_bsontype' in value) {
489+
if (isUint8Array(value)) {
490+
// '{"$binary":{"base64":"<base64 string>","subType":"XX"}}'
491+
// This is an estimate based on the fact that the base64 is approximately 1.33x the length of
492+
// the actual binary sequence https://en.wikipedia.org/wiki/Base64
493+
currentLength += (22 + value.byteLength + value.byteLength * 0.33 + 18) | 0;
494+
} else if ('_bsontype' in value) {
490495
const v = value as BSONObject;
491496
switch (v._bsontype) {
492497
case 'Int32':

0 commit comments

Comments
 (0)