diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-05-28 11:44:46 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-05-28 11:44:46 +0100 |
| commit | 2b87c2e4a31f80c467af1c5db0e9da3a6e1e508d (patch) | |
| tree | 69819cb306b820ffc12599ed6b7505878d8e5de5 /lib | |
| parent | 0d60c148c8fdb8168dcc6402021639572243f9cd (diff) | |
Introduce readAsText() on Image
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/documents.js | 6 | ||||
| -rw-r--r-- | lib/images.js | 2 | ||||
| -rw-r--r-- | lib/index.d.ts | 1 |
3 files changed, 8 insertions, 1 deletions
diff --git a/lib/documents.js b/lib/documents.js index 67e98af..26c0ce7 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -152,6 +152,12 @@ function Image(options) { return { type: types.image, read: options.readImage, + readAsText: function(encoding) { + if (!encoding) { + throw new Error("Missing encoding argument"); + } + return options.readImage(encoding); + }, altText: options.altText, contentType: options.contentType }; diff --git a/lib/images.js b/lib/images.js index fc45115..07cfc2d 100644 --- a/lib/images.js +++ b/lib/images.js @@ -23,7 +23,7 @@ function imgElement(func) { exports.inline = exports.imgElement; exports.dataUri = imgElement(function(element) { - return element.read("base64").then(function(imageBuffer) { + return element.readAsText("base64").then(function(imageBuffer) { return { src: "data:" + element.contentType + ";base64," + imageBuffer }; diff --git a/lib/index.d.ts b/lib/index.d.ts index d62aea9..9666a9e 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -39,6 +39,7 @@ interface ImageConverter { interface Image { contentType: string; + readAsText: (encoding: string) => Promise<string>; read: ImageRead; } |
