Encoder for GIF provides a Promise to getBuffer when a string, Buffer, or Uint8Array is expected #1239
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixing Issue 980: The 'chunk' argument must be of type string or an Instance of Buffer or Uint8Array. Received an instance of Promise.
What's Changing and Why
On jimp/packages/core/src/utils/image-bitmap.js getBuffer(mime, cb) function, the method is intended to provide a string or a buffer to a callback function so that the callback can consume such buffer (typically with the Write function).
However, occasionally the following error will occur ( see also #980 ):
I traced the issue back to the fact that one of the encoders, the GIF encoder, consistently returns a promise rather than a string or a buffer response. See jimp/packages/type-gif/src/index.js line 34.
Rather than solve this issue at the GIF encoder (if that could be solved at all), it seemed like a better idea to make the get buffer function more robust by permitting encoders to return a promise as a valid data type and handle such a response gracefully.
Accordingly, on jimp/packages/core/src/utils/image-bitmap.js getBuffer(mime, cb), I have added
What else might be affected
n/a