1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/ext/fetch
Luca Casonato 3b6b75bb46
feat(core): improve resource read & write traits (#16115)
This commit introduces two new buffer wrapper types to `deno_core`. The
main benefit of these new wrappers is that they can wrap a number of
different underlying buffer types. This allows for a more flexible read
and write API on resources that will require less copying of data
between different buffer representations.

- `BufView` is a read-only view onto a buffer. It can be backed by
`ZeroCopyBuf`, `Vec<u8>`, and `bytes::Bytes`.
- `BufViewMut` is a read-write view onto a buffer. It can be cheaply
converted into a `BufView`. It can be backed by `ZeroCopyBuf` or
`Vec<u8>`.

Both new buffer views have a cursor. This means that the start point of
the view can be constrained to write / read from just a slice of the
view. Only the start point of the slice can be adjusted. The end point
is fixed. To adjust the end point, the underlying buffer needs to be
truncated.

Readable resources have been changed to better cater to resources that
do not support BYOB reads. The basic `read` method now returns a
`BufView` instead of taking a `ZeroCopyBuf` to fill. This allows the
operation to return buffers that the resource has already allocated,
instead of forcing the caller to allocate the buffer. BYOB reads are
still very useful for resources that support them, so a new `read_byob`
method has been added that takes a `BufViewMut` to fill. `op_read`
attempts to use `read_byob` if the resource supports it, which falls
back to `read` and performs an additional copy if it does not. For
Rust->JS reads this change should have no impact, but for Rust->Rust
reads, this allows the caller to avoid an additional copy in many
scenarios. This combined with the support for `BufView` to be backed by
`bytes::Bytes` allows us to avoid one data copy when piping from a
`fetch` response into an `ext/http` response.

Writable resources have been changed to take a `BufView` instead of a
`ZeroCopyBuf` as an argument. This allows for less copying of data in
certain scenarios, as described above. Additionally a new
`Resource::write_all` method has been added that takes a `BufView` and
continually attempts to write the resource until the entire buffer has
been written. Certain resources like files can override this method to
provide a more efficient `write_all` implementation.
2022-10-09 14:49:25 +00:00
..
01_fetch_util.js chore: update copyright to 2022 (#13306) 2022-01-07 22:09:52 -05:00
20_headers.js feat: implement Web Cache API (#15829) 2022-09-28 17:41:12 +05:30
21_formdata.js fix(ext/fetch): support empty formdata (#16165) 2022-10-07 13:59:30 +02:00
22_body.js fix(ext/fetch): reject immediately on aborted signal (#16190) 2022-10-08 16:08:47 -04:00
22_http_client.js perf(ops): Monomorphic sync op calls (#15337) 2022-08-11 15:56:56 +02:00
23_request.js refactor(ext/fetch): avoid extra headers copy in .clone (#16130) 2022-10-03 13:34:13 +02:00
23_response.js refactor(ext/fetch): avoid extra headers copy in .clone (#16130) 2022-10-03 13:34:13 +02:00
26_fetch.js perf(ext/fetch): consume body using ops (#16038) 2022-10-04 15:48:50 +02:00
Cargo.toml chore: forward v1.26.1 release commit to main (#16178) 2022-10-06 16:49:40 -04:00
fs_fetch_handler.rs chore: update copyright to 2022 (#13306) 2022-01-07 22:09:52 -05:00
internal.d.ts chore: update copyright year (#13434) 2022-01-20 16:10:16 +09:00
lib.deno_fetch.d.ts docs: add permission tags to JSDocs (#15541) 2022-08-23 10:57:01 +10:00
lib.rs feat(core): improve resource read & write traits (#16115) 2022-10-09 14:49:25 +00:00
README.md Rename extensions/ directory to ext/ (#11643) 2021-08-11 12:27:05 +02:00

deno_fetch

This crate implements the Fetch API.

Spec: https://fetch.spec.whatwg.org/