Skip to content

Commit

Permalink
#166 Corrected check for valid image data. ArrayBuffers are now also …
Browse files Browse the repository at this point in the history
…valid image data containers, as the type definitions suggest.
  • Loading branch information
jjhbw committed Nov 13, 2020
1 parent d39b479 commit def88c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/processTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,15 @@ const imageToContext = (ctx: Context, img: Image) => {
};

function validateImage(img: Image) {
if (!(img.data instanceof Buffer || typeof img.data === 'string')) {
if (
!(
img.data instanceof Buffer ||
img.data instanceof ArrayBuffer ||
typeof img.data === 'string'
)
) {
throw new Error(
'image .data property needs to be provided as an ArrayBuffer-equivalent or as a base64-encoded string'
'image .data property needs to be provided as Buffer, ArrayBuffer, or as a base64-encoded string'
);
}
if (!ImageExtensions.includes(img.extension)) {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const ImageExtensions = [
export type ImageExtension = typeof ImageExtensions[number];
export type Image = {
extension: ImageExtension;
data: ArrayBuffer | string;
data: Buffer | ArrayBuffer | string;
};
export type Links = { [id: string]: Link };
export type Link = { url: string };
Expand Down

0 comments on commit def88c9

Please sign in to comment.