Skip to content

Commit

Permalink
fix: allocate a new Buffer for each chunk of a Blob stream when using…
Browse files Browse the repository at this point in the history
… hana-client (#846)
  • Loading branch information
BobdenOs authored Oct 16, 2024
1 parent 9530ee4 commit ec75b50
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hana/lib/drivers/hana-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ async function* rsIterator(rs, one) {
yield buffer
}

async function* streamBlob(rs, rowIndex = -1, columnIndex, binaryBuffer = Buffer.allocUnsafe(1 << 16)) {
async function* streamBlob(rs, rowIndex = -1, columnIndex, binaryBuffer) {
const promChain = {
resolve: () => { },
reject: () => { }
Expand Down Expand Up @@ -369,14 +369,14 @@ async function* streamBlob(rs, rowIndex = -1, columnIndex, binaryBuffer = Buffer
let blobPosition = 0

while (true) {
// REVISIT: Ensure that the data read is divisible by 3 as that allows for base64 encoding
const read = await getData(columnIndex, blobPosition, binaryBuffer, 0, binaryBuffer.byteLength)
const buffer = binaryBuffer || Buffer.allocUnsafe(1 << 16)
const read = await getData(columnIndex, blobPosition, buffer, 0, buffer.byteLength)
blobPosition += read
if (read < binaryBuffer.byteLength) {
yield binaryBuffer.subarray(0, read)
if (read < buffer.byteLength) {
yield buffer.subarray(0, read)
break
}
yield binaryBuffer
yield buffer
}
} catch (e) {
promChain.reject(e)
Expand Down

0 comments on commit ec75b50

Please sign in to comment.