MCPcopy Create free account
hub / github.com/nodejs/node / forgivingBase64

Function forgivingBase64

deps/undici/undici.js:4258–4277  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

4256 __name(collectASequenceOfCodePointsFast, "collectASequenceOfCodePointsFast");
4257 var ASCII_WHITESPACE_REPLACE_REGEX = /[\u0009\u000A\u000C\u000D\u0020]/g;
4258 function forgivingBase64(data) {
4259 data = data.replace(ASCII_WHITESPACE_REPLACE_REGEX, "");
4260 let dataLength = data.length;
4261 if (dataLength % 4 === 0) {
4262 if (data.charCodeAt(dataLength - 1) === 61) {
4263 --dataLength;
4264 if (data.charCodeAt(dataLength - 1) === 61) {
4265 --dataLength;
4266 }
4267 }
4268 }
4269 if (dataLength % 4 === 1) {
4270 return "failure";
4271 }
4272 if (/[^+/0-9A-Za-z]/.test(data.length === dataLength ? data : data.substring(0, dataLength))) {
4273 return "failure";
4274 }
4275 const buffer = Buffer.from(data, "base64");
4276 return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
4277 }
4278 __name(forgivingBase64, "forgivingBase64");
4279 function isASCIIWhitespace(char) {
4280 return char === 9 || // \t

Callers 1

dataURLProcessorFunction · 0.70

Calls 2

testMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected