summaryrefslogtreecommitdiff
path: root/core/ops_builtin.rs
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2022-10-10 10:28:35 +0200
committerGitHub <noreply@github.com>2022-10-10 10:28:35 +0200
commit1ab3691b091e34ffa5a0b8f2cd18a87da8c4930c (patch)
tree919c07adfc4f1f9818ec6827adedf17d7a71e2f5 /core/ops_builtin.rs
parent4d6aed1b528efc9bdac7cce7922259f5c703ec55 (diff)
feat(core): add Deno.core.writeAll(rid, chunk) (#16228)
This commit adds a new op_write_all to core that allows writing an entire chunk in a single async op call. Internally this calls `Resource::write_all`. The `writableStreamForRid` has been moved to `06_streams.js` now, and uses this new op. Various other code paths now also use this new op. Closes #16227
Diffstat (limited to 'core/ops_builtin.rs')
-rw-r--r--core/ops_builtin.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs
index 41741bf28..3fc9d62d6 100644
--- a/core/ops_builtin.rs
+++ b/core/ops_builtin.rs
@@ -38,6 +38,7 @@ pub(crate) fn init_builtins() -> Extension {
op_read::decl(),
op_read_all::decl(),
op_write::decl(),
+ op_write_all::decl(),
op_shutdown::decl(),
op_metrics::decl(),
op_format_file_name::decl(),
@@ -254,6 +255,18 @@ async fn op_write(
}
#[op]
+async fn op_write_all(
+ state: Rc<RefCell<OpState>>,
+ rid: ResourceId,
+ buf: ZeroCopyBuf,
+) -> Result<(), Error> {
+ let resource = state.borrow().resource_table.get_any(rid)?;
+ let view = BufView::from(buf);
+ resource.write_all(view).await?;
+ Ok(())
+}
+
+#[op]
async fn op_shutdown(
state: Rc<RefCell<OpState>>,
rid: ResourceId,