MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / blob2base64

Function blob2base64

src/common/util.js:104–115  ·  view source on GitHub ↗
(blob, offset = 0, length = 1e99)

Source from the content-addressed store, hash-verified

102 * @return {string | Promise<string>} base64-encoded contents
103 */
104export function blob2base64(blob, offset = 0, length = 1e99) {
105 if (offset || length < blob.size) {
106 blob = blob.slice(offset, offset + length);
107 }
108 if (!blob.size) {
109 return '';
110 }
111 if (U8_fromBase64) {
112 return blob.arrayBuffer().then(buf => new Uint8Array(buf).toBase64());
113 }
114 return readBlob(blob).then(res => res.slice(res.indexOf(',') + 1));
115}
116
117export function dataUri2text(url) {
118 const i = url.indexOf(','); // a non-base64 data: uri may have many `,`

Callers 2

blob2chunkFunction · 0.90
makeRawFunction · 0.90

Calls 1

readBlobFunction · 0.85

Tested by

no test coverage detected