We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 69fd146 commit a00562cCopy full SHA for a00562c
src/Asset.js
@@ -1,5 +1,15 @@
1
const TextDecoder = require('text-encoding').TextDecoder;
2
3
+const memoizedToString = (function () {
4
+ const strings = {};
5
+ return (assetId, data) => {
6
+ if (!strings.hasOwnProperty(assetId)) {
7
+ strings[assetId] = data.toString('base64');
8
+ }
9
+ return strings[assetId];
10
+ };
11
+}());
12
+
13
class Asset {
14
/**
15
* Construct an Asset.
@@ -47,7 +57,7 @@ class Asset {
47
57
*/
48
58
encodeDataURI (contentType) {
49
59
contentType = contentType || this.assetType.contentType;
50
- return `data:${contentType};base64,${this.data.toString('base64')}`;
60
+ return `data:${contentType};base64,${memoizedToString(this.assetId, this.data)}`;
51
61
}
52
62
53
63
0 commit comments