From 0a404cac937c4298d3c88e20281dc647945e51cd Mon Sep 17 00:00:00 2001 From: Zach Stevenson <71655313+stevezac-osu@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:01:57 -0400 Subject: [PATCH] Encoder for GIF provides a Promise to getBuffer when a string, Buffer, or Uint8Array is expected (#1239) * Fixing Issue 980: The 'chunk' argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Promise. * fix lint --------- Co-authored-by: Andrew Lisowski --- packages/core/src/utils/image-bitmap.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/image-bitmap.js b/packages/core/src/utils/image-bitmap.js index 6b2717d11..fe377cbd9 100644 --- a/packages/core/src/utils/image-bitmap.js +++ b/packages/core/src/utils/image-bitmap.js @@ -225,7 +225,15 @@ export function getBuffer(mime, cb) { if (this.constructor.encoders[mime]) { const buffer = this.constructor.encoders[mime](this); - cb.call(this, null, buffer); + // Typically, buffers return a string or map. However, the gif library "gifwrap" seemingly returns promises. + if (buffer instanceof Promise) { + // trigger the callback when the promise has been resolved + buffer.then((buff) => { + cb.call(this, null, buff); + }); + } else { + cb.call(this, null, buffer); + } } else { return throwError.call(this, "Unsupported MIME type: " + mime, cb); }