MCPcopy Create free account
hub / github.com/denoland/std / constructor

Method constructor

http/unstable_formdata_decoder_stream.ts:73–96  ·  view source on GitHub ↗

* Constructs a new instance. * * @param contentType The content type of the form data. * @param readable The readable stream of the form data.

(contentType: string, readable: ReadableStream<Uint8Array>)

Source from the content-addressed store, hash-verified

71 * @param readable The readable stream of the form data.
72 */
73 constructor(contentType: string, readable: ReadableStream<Uint8Array>) {
74 let boundary: string | Uint8Array | undefined = contentType
75 .split(";")
76 .find((x) => x.trimStart().startsWith("boundary="))
77 ?.split("=")[1];
78 if (boundary == undefined) {
79 throw TypeError("Boundary not found in contentType");
80 }
81 if (boundary.startsWith('"')) boundary = boundary.slice(1, -1);
82 boundary = "--" + boundary;
83 // Only ASCII Characters are allowed within the boundary.
84 // *Presumably* if the UTF-16 length of the boundary does not match that of
85 // the characters encoded then the boundary contained non-ASCII characters.
86 if (
87 boundary.length !==
88 new TextEncoder()
89 .encodeInto(
90 boundary,
91 boundary = new Uint8Array(boundary.length),
92 )
93 .read
94 ) throw new SyntaxError("Boundary has invalid characters within it");
95 this.#readable = ReadableStream.from(this.#handle(readable, boundary));
96 }
97
98 async *#handle(
99 readable: ReadableStream<Uint8Array>,

Callers

nothing calls this directly

Calls 5

#handleMethod · 0.95
startsWithMethod · 0.80
findMethod · 0.45
sliceMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected