(blob, offset = 0, length = 1e99)
| 102 | * @return {string | Promise<string>} base64-encoded contents |
| 103 | */ |
| 104 | export 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 | |
| 117 | export function dataUri2text(url) { |
| 118 | const i = url.indexOf(','); // a non-base64 data: uri may have many `,` |
no test coverage detected