MCPcopy Index your code
hub / github.com/sql-js/sql.js / intArrayFromBase64

Function intArrayFromBase64

js/sql-debug.js:5442–5463  ·  view source on GitHub ↗
(s)

Source from the content-addressed store, hash-verified

5440// Converts a string of base64 into a byte array.
5441// Throws error on invalid input.
5442function intArrayFromBase64(s) {
5443 if (typeof ENVIRONMENT_IS_NODE === 'boolean' && ENVIRONMENT_IS_NODE) {
5444 var buf;
5445 try {
5446 buf = Buffer.from(s, 'base64');
5447 } catch (_) {
5448 buf = new Buffer(s, 'base64');
5449 }
5450 return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
5451 }
5452
5453 try {
5454 var decoded = decodeBase64(s);
5455 var bytes = new Uint8Array(decoded.length);
5456 for (var i = 0 ; i < decoded.length ; ++i) {
5457 bytes[i] = decoded.charCodeAt(i);
5458 }
5459 return bytes;
5460 } catch (_) {
5461 throw new Error('Converting base64 string to bytes failed.');
5462 }
5463}
5464
5465// If filename is a base64 data URI, parses and returns data (Buffer on node,
5466// Uint8Array otherwise). If filename is not a base64 data URI, returns undefined.

Callers 1

tryParseAsDataURIFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…