aboutsummaryrefslogtreecommitdiff
path: root/lib/documents.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-05-28 12:24:16 +0100
committerMichael Williamson <mike@zwobble.org>2023-05-28 12:24:16 +0100
commitb2b2c35715985f624e6b696fd87140fa6056318f (patch)
treea8015940e1d4b4bae1422af8e99277126e1df029 /lib/documents.js
parent1ce7c085668fd978f4f343b41db7f76f33145de5 (diff)
Avoid use of Buffer
Diffstat (limited to 'lib/documents.js')
-rw-r--r--lib/documents.js20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/documents.js b/lib/documents.js
index 26c0ce7..9088ed9 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -151,12 +151,22 @@ function noteKey(noteType, id) {
function Image(options) {
return {
type: types.image,
- read: options.readImage,
- readAsText: function(encoding) {
- if (!encoding) {
- throw new Error("Missing encoding argument");
+ // `read` is retained for backwards compatibility, but other read
+ // methods should be preferred.
+ read: function(encoding) {
+ if (encoding) {
+ return options.readImage(encoding);
+ } else {
+ return options.readImage().then(function(arrayBuffer) {
+ return Buffer.from(arrayBuffer);
+ });
}
- return options.readImage(encoding);
+ },
+ readAsArrayBuffer: function() {
+ return options.readImage();
+ },
+ readAsBase64String: function() {
+ return options.readImage("base64");
},
altText: options.altText,
contentType: options.contentType