MCPcopy Create free account
hub / github.com/ading2210/linuxpdf / b64_to_uint8array

Function b64_to_uint8array

file_template.js:2–13  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

1//https://stackoverflow.com/a/41106346/21330993
2function b64_to_uint8array(str) {
3 const abc = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"]; // base64 alphabet
4 let result = [];
5
6 for(let i=0; i<str.length/4; i++) {
7 let chunk = [...str.slice(4*i,4*i+4)]
8 let bin = chunk.map(x=> abc.indexOf(x).toString(2).padStart(6,0)).join('');
9 let bytes = bin.match(/.{1,8}/g).map(x=> +('0b'+x));
10 result.push(...bytes.slice(0,3 - (str[4*i+2]=="=") - (str[4*i+3]=="=")));
11 }
12 return new Uint8Array(result);
13}
14
15var embedded_files = __files_data__;
16for (let filename in embedded_files) {

Callers 1

file_template.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected