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

Method pull

http/unstable_formdata_decoder_stream.ts:183–235  ·  view source on GitHub ↗
(controller)

Source from the content-addressed store, hash-verified

181 type: "bytes",
182 autoAllocateChunkSize: 1024 * 8,
183 async pull(controller) {
184 const length = controller.byobRequest!.view!.byteLength;
185 const buf = new Uint8Array(
186 controller.byobRequest!.view!.buffer,
187 controller.byobRequest!.view!.byteOffset,
188 length,
189 );
190
191 let written = 0;
192 while (true) {
193 const v = (await reader.read()).value;
194 if (v == undefined) {
195 error(new SyntaxError("Unexpected EOF"));
196 return controller.error(new SyntaxError("Unexpected EOF"));
197 }
198 if (
199 v.value.length >= boundary.length &&
200 boundary.every((x, i) => x === v.value[i])
201 ) {
202 buffer = v.value;
203 releaseLock();
204 controller.close();
205 return controller.byobRequest!.respond(0);
206 }
207
208 if (pMatch) {
209 if (length - written === 1) {
210 buf[written] = 13;
211 controller.byobRequest!.respond(written + 1);
212 controller.enqueue(Uint8Array.from([10]));
213 return controller.enqueue(v.value);
214 }
215 buf.set([13, 10], written);
216 written += 2;
217 }
218
219 if (v.value.length + written) {
220 if (v.value.length > length - written) {
221 buf.set(v.value.subarray(0, length - written), written);
222 controller.byobRequest!.respond(length);
223 controller.enqueue(v.value.subarray(length - written));
224 } else {
225 buf.set(v.value, written);
226 written += v.value.length;
227 controller.byobRequest!.respond(written);
228 }
229 pMatch = v.match;
230 return;
231 }
232 // Only loops if body starts with \r\n
233 pMatch = v.match;
234 }
235 },
236 async cancel() {
237 do {
238 buffer = (await reader.read()).value?.value;

Callers

nothing calls this directly

Calls 5

errorFunction · 0.85
readMethod · 0.65
closeMethod · 0.65
setMethod · 0.65
fromMethod · 0.45

Tested by

no test coverage detected