From 8e3c6c23d7c6341c82565711eedd7639f5e27bb6 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Tue, 21 May 2024 14:56:17 -0500 Subject: [PATCH] Update conversion of Uint8Array to Readable for in-memory attachments Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com> --- ts/AttachmentCrypto.ts | 2 +- ts/test-electron/Crypto_test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ts/AttachmentCrypto.ts b/ts/AttachmentCrypto.ts index a6ebe283b6..c7bc4e8373 100644 --- a/ts/AttachmentCrypto.ts +++ b/ts/AttachmentCrypto.ts @@ -126,7 +126,7 @@ export async function encryptAttachmentV2({ try { const source = 'data' in plaintext - ? Readable.from(plaintext.data) + ? Readable.from([Buffer.from(plaintext.data)]) : createReadStream(plaintext.absolutePath); await pipeline( diff --git a/ts/test-electron/Crypto_test.ts b/ts/test-electron/Crypto_test.ts index 695558a1da..b6bc947a0f 100644 --- a/ts/test-electron/Crypto_test.ts +++ b/ts/test-electron/Crypto_test.ts @@ -675,6 +675,12 @@ describe('Crypto', () => { data: FILE_CONTENTS, plaintextHash: FILE_HASH, }); + + // also works if data is raw Uint8Array rather than a buffer + await testV2RoundTripData({ + data: new Uint8Array(FILE_CONTENTS), + plaintextHash: FILE_HASH, + }); }); it('v2 roundtrips large file from disk', async () => {