mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04: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;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
|
|
Loading…
Reference in a new issue