MCPcopy Index your code
hub / github.com/nodejs/node / dataURLProcessor

Function dataURLProcessor

lib/internal/data_url.js:35–132  ·  view source on GitHub ↗

* @param {URL} dataURL * @returns {object|'failure'}

(dataURL)

Source from the content-addressed store, hash-verified

33 * @returns {object|'failure'}
34 */
35function dataURLProcessor(dataURL) {
36 // 1. Assert: dataURL's scheme is "data".
37 assert(dataURL.protocol === 'data:');
38
39 // 2. Let input be the result of running the URL
40 // serializer on dataURL with exclude fragment
41 // set to true.
42 let input = URLSerializer(dataURL, true);
43
44 // 3. Remove the leading "data:" string from input.
45 input = StringPrototypeSlice(input, 5);
46
47 // 4. Let position point at the start of input.
48 const position = { position: 0 };
49
50 // 5. Let mimeType be the result of collecting a
51 // sequence of code points that are not equal
52 // to U+002C (,), given position.
53 let mimeType = collectASequenceOfCodePointsFast(
54 ',',
55 input,
56 position,
57 );
58
59 // 6. Strip leading and trailing ASCII whitespace
60 // from mimeType.
61 // Undici implementation note: we need to store the
62 // length because if the mimetype has spaces removed,
63 // the wrong amount will be sliced from the input in
64 // step #9
65 const mimeTypeLength = mimeType.length;
66 mimeType = removeASCIIWhitespace(mimeType, true, true);
67
68 // 7. If position is past the end of input, then
69 // return failure
70 if (position.position >= input.length) {
71 return 'failure';
72 }
73
74 // 8. Advance position by 1.
75 position.position++;
76
77 // 9. Let encodedBody be the remainder of input.
78 const encodedBody = StringPrototypeSlice(input, mimeTypeLength + 1);
79
80 // 10. Let body be the percent-decoding of encodedBody.
81 let body = stringPercentDecode(encodedBody);
82
83 // 11. If mimeType ends with U+003B (;), followed by
84 // zero or more U+0020 SPACE, followed by an ASCII
85 // case-insensitive match for "base64", then:
86 if (RegExpPrototypeExec(/;(\u0020){0,}base64$/i, mimeType) !== null) {
87 // 1. Let stringBody be the isomorphic decode of body.
88 const stringBody = isomorphicDecode(body);
89
90 // 2. Set body to the forgiving-base64 decode of
91 // stringBody.
92 body = forgivingBase64(stringBody);

Callers 1

getSourceSyncFunction · 0.50

Calls 7

assertFunction · 0.70
URLSerializerFunction · 0.70
removeASCIIWhitespaceFunction · 0.70
stringPercentDecodeFunction · 0.70
isomorphicDecodeFunction · 0.70
forgivingBase64Function · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…