MCPcopy Create free account
hub / github.com/awslabs/llrt / from_bytes

Method from_bytes

modules/llrt_buffer/src/file.rs:101–125  ·  view source on GitHub ↗
(
        ctx: &Ctx<'js>,
        data: Vec<u8>,
        filename: String,
        mime_type: Option<String>,
    )

Source from the content-addressed store, hash-verified

99
100impl<'js> File<'js> {
101 pub fn from_bytes(
102 ctx: &Ctx<'js>,
103 data: Vec<u8>,
104 filename: String,
105 mime_type: Option<String>,
106 ) -> Result<Self> {
107 let options = Opt(Some({
108 let obj = Object::new(ctx.clone())?;
109 obj.set("type", mime_type.clone().unwrap_or("".into()).into_js(ctx)?)?;
110 obj.into_js(ctx)?
111 }));
112 let blob = Blob::from_parts(ctx.clone(), Opt(Some(data.into_js(ctx)?)), options)?;
113
114 Ok(Self {
115 blob,
116 filename,
117 last_modified: time::now_millis(),
118 })
119 }
120
121 pub fn get_blob(&self) -> Blob<'js> {
122 self.blob.clone()
123 }
124
125 pub fn set_filename(&mut self, filename: String) {
126 self.filename = filename;
127 }
128}

Callers

nothing calls this directly

Calls 4

now_millisFunction · 0.85
cloneMethod · 0.45
setMethod · 0.45
into_jsMethod · 0.45

Tested by

no test coverage detected