From 75512b835f536b94ebad88e50ce400e38fc257e8 Mon Sep 17 00:00:00 2001 From: LijieZhang1998 Date: Wed, 8 Oct 2025 16:41:22 -0500 Subject: [PATCH] STREAMS-1964: Add old shell compatibility of BinData for JS Engine --- snippets/mongocompat/mongotypes.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/snippets/mongocompat/mongotypes.js b/snippets/mongocompat/mongotypes.js index e790fb2..49b61bc 100644 --- a/snippets/mongocompat/mongotypes.js +++ b/snippets/mongocompat/mongotypes.js @@ -542,6 +542,31 @@ if (typeof (BinData) != "undefined") { BinData.prototype.length = function() { return this.len; }; + + BinData.prototype.nativeToString = BinData.prototype.toString; + BinData.prototype.toString = function (encoding) { + if (encoding) { + return this.nativeToString(encoding); + } + return `BinData(${this.type}, ${this.base64()})`; + }; + + BinData.prototype.base64 = function () { + return this.toString("base64"); + }; + BinData.prototype.hex = function () { + return this.toString("hex"); + }; + Object.defineProperty(BinData.prototype, "len", { + get: function () { + return this.buffer ? this.buffer.byteLength : 0; + }, + }); + Object.defineProperty(BinData.prototype, "type", { + get: function () { + return this.sub_type; + }, + }); } else { print("warning: no BinData class"); }