diff options
author | Luca Casonato <hello@lcas.dev> | 2023-04-06 00:14:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-06 00:14:16 +0200 |
commit | 36e8c8dfd759458aa735f79f5cc7cd346c727914 (patch) | |
tree | ca8065958c406c02a8daa56f5056a658c813839f /ext/io/12_io.js | |
parent | ee15b49845b9cbe1f8ea75372091931fa460ad0d (diff) |
feat(core): sync io ops in core (#18603)
This commit adds op_read_sync and op_write_sync to core. These ops are
similar to op_read and op_write, but they are synchronous. Just like the
async ops, they operate on generic `deno_core::Resource` objects. These
now have new `read_byob_sync` and `write_sync` methods, with default
implementations throwing "NotSupported" errors, just like the async
counterparts.
There are no `write_all` or `read` equivalents, because the
optimizations they unlock are not useful in synchronous contexts.
Diffstat (limited to 'ext/io/12_io.js')
-rw-r--r-- | ext/io/12_io.js | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/ext/io/12_io.js b/ext/io/12_io.js index 2a825e7f6..1bb8f9fba 100644 --- a/ext/io/12_io.js +++ b/ext/io/12_io.js @@ -93,27 +93,19 @@ function* iterSync( } function readSync(rid, buffer) { - if (buffer.length === 0) { - return 0; - } - - const nread = ops.op_read_sync(rid, buffer); - + if (buffer.length === 0) return 0; + const nread = core.readSync(rid, buffer); return nread === 0 ? null : nread; } async function read(rid, buffer) { - if (buffer.length === 0) { - return 0; - } - + if (buffer.length === 0) return 0; const nread = await core.read(rid, buffer); - return nread === 0 ? null : nread; } function writeSync(rid, data) { - return ops.op_write_sync(rid, data); + return core.writeSync(rid, data); } function write(rid, data) { |