diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-04-26 09:26:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 09:26:05 -0400 |
commit | 3c7c5865778360aeb2b1285a414d1f8d878d7a22 (patch) | |
tree | 519dca4c95f37f60f7f5e1dabcdddc5df4515d1e /runtime/ops/io.rs | |
parent | dc4ab1d9340a58f81beab24ef211e900acbb9ad8 (diff) |
refactor(ops/process): add `StdioOrRid` enum (#14393)
Diffstat (limited to 'runtime/ops/io.rs')
-rw-r--r-- | runtime/ops/io.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index 34cd541d5..d54c66efd 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -1,5 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use deno_core::error::bad_resource_id; use deno_core::error::not_supported; use deno_core::error::resource_unavailable; use deno_core::error::AnyError; @@ -330,6 +331,16 @@ impl StdFileResource { None => Err(resource_unavailable()), } } + + pub fn clone_file( + state: &mut OpState, + rid: ResourceId, + ) -> Result<std::fs::File, AnyError> { + Self::with(state, rid, move |r| match r { + Ok(std_file) => std_file.try_clone().map_err(AnyError::from), + Err(_) => Err(bad_resource_id()), + }) + } } impl Resource for StdFileResource { |