gio
gio
DDeno
Created by Ami on 12/28/2023 in #help
Updated examples for "Roll your own JavaScript runtime" blog posts?
Hi! I'm in the same boat as you but I'm on part 3 trying to figure out snapshotting. I was able to finish part 1 by looking at example ops over at https://docs.rs/crate/deno_url/latest/source/lib.rs
#[op2(async)]
#[string]
pub async fn op_read_file(#[string] path: String) -> Result<String, Error> {
let contents = tokio::fs::read_to_string(path).await?;
Ok(contents)
}

#[op2(async)]
pub async fn op_write_file(
#[string] path: String,
#[string] contents: String,
) -> Result<(), Error> {
tokio::fs::write(path, contents).await?;
Ok(())
}

#[op2(fast)]
pub fn op_remove_file(#[string] path: String) -> Result<(), Error> {
std::fs::remove_file(path)?;
Ok(())
}
#[op2(async)]
#[string]
pub async fn op_read_file(#[string] path: String) -> Result<String, Error> {
let contents = tokio::fs::read_to_string(path).await?;
Ok(contents)
}

#[op2(async)]
pub async fn op_write_file(
#[string] path: String,
#[string] contents: String,
) -> Result<(), Error> {
tokio::fs::write(path, contents).await?;
Ok(())
}

#[op2(fast)]
pub fn op_remove_file(#[string] path: String) -> Result<(), Error> {
std::fs::remove_file(path)?;
Ok(())
}
and
let runjs_extension = Extension {
ops: vec![
op_read_file::DECL,
op_write_file::DECL,
op_remove_file::DECL,
op_fetch::DECL,
]
.into(),
..Default::default()
};
let runjs_extension = Extension {
ops: vec![
op_read_file::DECL,
op_write_file::DECL,
op_remove_file::DECL,
op_fetch::DECL,
]
.into(),
..Default::default()
};
9 replies