* 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>)
| 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>, |
nothing calls this directly
no test coverage detected