Skip to content

Commit

Permalink
doc: improve documentation for consuming request body (denoland/deno#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cknight authored May 28, 2020
1 parent 6fbc974 commit 847ab7b
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 847ab7b

Please sign in to comment.