1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

doc: improve documentation for consuming request body (#5771)

This commit is contained in:
Chris Knight 2020-05-28 18:36:18 +01:00 committed by GitHub
parent dc6c07e3ed
commit 86c6f05404
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -53,18 +53,9 @@ export class ServerRequest {
private _body: Deno.Reader | null = null;
/**
* Body of the request.
* Body of the request. The easiest way to consume the body is:
*
* const buf = new Uint8Array(req.contentLength);
* let bufSlice = buf;
* let totRead = 0;
* while (true) {
* const nread = await req.body.read(bufSlice);
* if (nread === null) break;
* totRead += nread;
* if (totRead >= req.contentLength) break;
* bufSlice = bufSlice.subarray(nread);
* }
* const buf: Uint8Array = await Deno.readAll(req.body);
*/
get body(): Deno.Reader {
if (!this._body) {