How to save TaggedFile
to Vec<u8>
?
#293
-
I am new to Rust and want to build a wasm version of this awesome project, see #289 I am facing a problem of how to save Any help is highly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
It's a WIP, see #290. I looked into WASM after you submitted #289. I had no experience with it prior and did not know it doesn't have access to |
Beta Was this translation helpful? Give feedback.
-
Hey👋 Is there any way to save without cloning the original buffer? #[wasm_bindgen]
pub struct MetaFile {
buffer: Vec<u8>,
tag: Tag,
}
#[wasm_bindgen]
impl MetaFile {
#[wasm_bindgen(constructor)]
pub fn new(buf: Vec<u8>) -> Self {
set_panic_hook();
let tagged_file = Probe::new(Cursor::new(buf.clone()))
.guess_file_type()
.expect("fail to guess file type")
.read()
.expect("fail to read file");
MetaFile {
buffer: buf,
tag: tagged_file.primary_tag().cloned().unwrap_or_else(|| {
tagged_file
.first_tag()
.cloned()
.expect("ERROR: No tags found!")
}),
}
}
// other tags...
#[wasm_bindgen]
pub fn save(&mut self) -> () {
// is .clone Avoidable?
let mut buf = Cursor::new(self.buffer.clone());
let _ = self.tag.save_to(&mut buf, WriteOptions::default());
self.buffer = buf.into_inner();
}
} the suggested solution is below, but errors #[wasm_bindgen]
pub fn save(&mut self) -> () {
set_panic_hook();
let mut buf = Cursor::new(&mut self.buffer);
self.tag.save_to(&mut buf, WriteOptions::default());
} What is the correct way to implement it? |
Beta Was this translation helpful? Give feedback.
-
Finally open source it: https://github.com/subframe7536/music-metadata-wasm |
Beta Was this translation helpful? Give feedback.
Should be good now, try with 0.19.2