MCPcopy Index your code
hub / github.com/angular/angular / toBase64

Function toBase64

packages/common/http/src/transfer_cache.ts:404–418  ·  view source on GitHub ↗
(buffer: unknown)

Source from the content-addressed store, hash-verified

402}
403
404function toBase64(buffer: unknown): string {
405 //TODO: replace with when is Baseline widely available
406 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64
407 const bytes = new Uint8Array(buffer as ArrayBufferLike);
408
409 const CHUNK_SIZE = 0x8000; // 32,768 bytes (~32 KB) per chunk, to avoid stack overflow
410
411 let binaryString = '';
412
413 for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {
414 const chunk = bytes.subarray(i, i + CHUNK_SIZE);
415 binaryString += String.fromCharCode.apply(null, chunk as unknown as number[]);
416 }
417 return btoa(binaryString);
418}
419
420function fromBase64(base64: string): ArrayBuffer {
421 const binary = atob(base64);

Callers 1

Calls 1

applyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…