From 4f1d9492c539591bad36573870ff83faea3a6f56 Mon Sep 17 00:00:00 2001 From: Ilya Borodin Date: Sat, 20 Aug 2022 13:36:54 +0300 Subject: [PATCH] Changed concat to push --- src/Utils/chat-utils.ts | 6 +++--- src/Utils/history.ts | 6 ++++-- src/Utils/messages.ts | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index 48076ac..782fa94 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -330,12 +330,12 @@ export const extractSyncdPatches = async(result: BinaryNode) => { export const downloadExternalBlob = async(blob: proto.IExternalBlobReference) => { const stream = await downloadContentFromMessage(blob, 'md-app-state') - let buffer = Buffer.from([]) + const bufferArray: Buffer[] = [] for await (const chunk of stream) { - buffer = Buffer.concat([buffer, chunk]) + bufferArray.push(chunk) } - return buffer + return Buffer.concat(bufferArray) } export const downloadExternalPatch = async(blob: proto.IExternalBlobReference) => { diff --git a/src/Utils/history.ts b/src/Utils/history.ts index 32ddf5e..790bd87 100644 --- a/src/Utils/history.ts +++ b/src/Utils/history.ts @@ -11,11 +11,13 @@ const inflatePromise = promisify(inflate) export const downloadHistory = async(msg: proto.Message.IHistorySyncNotification) => { const stream = await downloadContentFromMessage(msg, 'history') - let buffer = Buffer.from([]) + const bufferArray: Buffer[] = [] for await (const chunk of stream) { - buffer = Buffer.concat([buffer, chunk]) + bufferArray.push(chunk) } + let buffer = Buffer.concat(bufferArray) + // decompress buffer buffer = await inflatePromise(buffer) diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index cb9e4fc..ce6e533 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -702,12 +702,12 @@ export const downloadMediaMessage = async( const stream = await downloadContentFromMessage(media, mediaType, options) if(type === 'buffer') { - let buffer = Buffer.from([]) + const bufferArray: Buffer[] = [] for await (const chunk of stream) { - buffer = Buffer.concat([buffer, chunk]) + bufferArray.push(chunk) } - return buffer + return Buffer.concat(bufferArray) } return stream