mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
doc: improve documentation for consuming request body (#5771)
This commit is contained in:
parent
dc6c07e3ed
commit
86c6f05404
1 changed files with 2 additions and 11 deletions
|
@ -53,18 +53,9 @@ export class ServerRequest {
|
||||||
private _body: Deno.Reader | null = null;
|
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);
|
* const buf: Uint8Array = await Deno.readAll(req.body);
|
||||||
* 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);
|
|
||||||
* }
|
|
||||||
*/
|
*/
|
||||||
get body(): Deno.Reader {
|
get body(): Deno.Reader {
|
||||||
if (!this._body) {
|
if (!this._body) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue