pub struct RiffFile { /* private fields */ }
Expand description
RIFF file
Implementations§
Source§impl RiffFile
Resource Interchange File Format
impl RiffFile
Resource Interchange File Format
Sourcepub fn open(filename: &str) -> Result<Self>
pub fn open(filename: &str) -> Result<Self>
Open a RIFF file from a filename
Examples found in repository?
examples/view.rs (line 18)
10fn main() -> Result<()> {
11 if env::args().len() < 2 {
12 println!("Usage: view [filename]");
13 exit(-1);
14 }
15
16 let filename = env::args().nth(1).unwrap();
17
18 let file = RiffFile::open(&filename)?;
19
20 println!("File type: {}", format_fourcc(file.file_type()));
21 println!("File size: {}", file.file_size());
22
23 show_entry(&file.read_file()?, 0, file.bytes())?;
24 Ok(())
25}
More examples
examples/copy.rs (line 20)
11fn main() -> Result<()> {
12 if env::args().len() < 2 {
13 println!("Usage: copy [source] [desy]");
14 exit(-1);
15 }
16
17 let filename_src = env::args().nth(1).unwrap();
18 let filename_dst = env::args().nth(2).unwrap();
19
20 let file = RiffFile::open(&filename_src)?;
21 let mut outfile = File::create(&filename_dst)?;
22
23 let toplevel = file.read_file()?;
24 toplevel.to_owned(file.bytes()).write(&mut outfile)?;
25
26 Ok(())
27}
examples/copy_metadata.rs (line 53)
43fn main() -> Result<()> {
44 if env::args().len() < 2 {
45 println!("Usage: copy [source] [desy]");
46 exit(-1);
47 }
48
49 let filename_src = env::args().nth(1).unwrap();
50 let filename_base = env::args().nth(2).unwrap();
51 let filename_new = env::args().nth(3).unwrap();
52
53 let file = RiffFile::open(&filename_src)?;
54 let toplevel = file.read_file()?;
55 let avif_chunk = find_chunk(
56 &toplevel,
57 &|c: &Chunk<DataRef>| {
58 let b = c.bytes(file.bytes());
59 &c.id == b"strd" && &b[..4] == b"AVIF"
60 },
61 ).unwrap();
62 let avif_chunk = avif_chunk.to_owned(file.bytes());
63 let avif_chunk = Entry::Chunk(avif_chunk);
64 let name_chunk = find_chunk(
65 &toplevel,
66 &|c: &Chunk<DataRef>| {
67 let b = c.bytes(file.bytes());
68 &c.id == b"strn" && &b[..4] == b"FUJI"
69 },
70 ).unwrap();
71 let name_chunk = name_chunk.to_owned(file.bytes());
72 let name_chunk = Entry::Chunk(name_chunk);
73
74
75 let file = RiffFile::open(&filename_base)?;
76 let toplevel = file.read_file()?.to_owned(file.bytes());
77
78 let new_toplevel = walk(toplevel, &|e| match e {
79 Entry::List(l) if &l.list_type == b"strl" => {
80 let mut l = l.clone();
81 let avif_chunk = avif_chunk.clone();
82 let position = l.children.iter().position(|e| match e {
83 Entry::Chunk(c) if &c.id == b"strd" => true,
84 _ => false,
85 });
86 match position {
87 Some(p) => {
88 l.children[p] = avif_chunk;
89 },
90 None => {
91 let pos = l.children.iter().position(|e| match e {
92 Entry::Chunk(c) if &c.id == b"strf" => true,
93 _ => false,
94 });
95 let pos = pos.map(|i| i + 1).unwrap_or(l.children.len());
96 l.children.insert(pos, avif_chunk);
97 },
98 };
99 let name_chunk = name_chunk.clone();
100 let position = l.children.iter().position(|e| match e {
101 Entry::Chunk(c) if &c.id == b"strn" => true,
102 _ => false,
103 });
104 match position {
105 Some(p) => {
106 l.children[p] = name_chunk;
107 },
108 None => {
109 let pos = l.children.iter().position(|e| match e {
110 Entry::Chunk(c) if &c.id == b"strd" => true,
111 _ => false,
112 });
113 let pos = pos.map(|i| i + 1).unwrap_or(l.children.len());
114 l.children.insert(pos, name_chunk);
115 },
116 };
117 Entry::List(l)
118 },
119 other => other,
120 });
121
122 let mut outfile = File::create(&filename_new)?;
123
124 new_toplevel.write(&mut outfile)?;
125
126 Ok(())
127}
Sourcepub fn open_with_file_handle(file: &File) -> Result<Self>
pub fn open_with_file_handle(file: &File) -> Result<Self>
Open a RIFF file from a File
handle
Sourcepub fn file_type(&self) -> &FourCC
pub fn file_type(&self) -> &FourCC
Examples found in repository?
examples/view.rs (line 20)
10fn main() -> Result<()> {
11 if env::args().len() < 2 {
12 println!("Usage: view [filename]");
13 exit(-1);
14 }
15
16 let filename = env::args().nth(1).unwrap();
17
18 let file = RiffFile::open(&filename)?;
19
20 println!("File type: {}", format_fourcc(file.file_type()));
21 println!("File size: {}", file.file_size());
22
23 show_entry(&file.read_file()?, 0, file.bytes())?;
24 Ok(())
25}
Sourcepub fn file_size(&self) -> usize
pub fn file_size(&self) -> usize
Examples found in repository?
examples/view.rs (line 21)
10fn main() -> Result<()> {
11 if env::args().len() < 2 {
12 println!("Usage: view [filename]");
13 exit(-1);
14 }
15
16 let filename = env::args().nth(1).unwrap();
17
18 let file = RiffFile::open(&filename)?;
19
20 println!("File type: {}", format_fourcc(file.file_type()));
21 println!("File size: {}", file.file_size());
22
23 show_entry(&file.read_file()?, 0, file.bytes())?;
24 Ok(())
25}
Sourcepub fn bytes(&self) -> &[u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
Examples found in repository?
examples/view.rs (line 23)
10fn main() -> Result<()> {
11 if env::args().len() < 2 {
12 println!("Usage: view [filename]");
13 exit(-1);
14 }
15
16 let filename = env::args().nth(1).unwrap();
17
18 let file = RiffFile::open(&filename)?;
19
20 println!("File type: {}", format_fourcc(file.file_type()));
21 println!("File size: {}", file.file_size());
22
23 show_entry(&file.read_file()?, 0, file.bytes())?;
24 Ok(())
25}
More examples
examples/copy.rs (line 24)
11fn main() -> Result<()> {
12 if env::args().len() < 2 {
13 println!("Usage: copy [source] [desy]");
14 exit(-1);
15 }
16
17 let filename_src = env::args().nth(1).unwrap();
18 let filename_dst = env::args().nth(2).unwrap();
19
20 let file = RiffFile::open(&filename_src)?;
21 let mut outfile = File::create(&filename_dst)?;
22
23 let toplevel = file.read_file()?;
24 toplevel.to_owned(file.bytes()).write(&mut outfile)?;
25
26 Ok(())
27}
examples/copy_metadata.rs (line 58)
43fn main() -> Result<()> {
44 if env::args().len() < 2 {
45 println!("Usage: copy [source] [desy]");
46 exit(-1);
47 }
48
49 let filename_src = env::args().nth(1).unwrap();
50 let filename_base = env::args().nth(2).unwrap();
51 let filename_new = env::args().nth(3).unwrap();
52
53 let file = RiffFile::open(&filename_src)?;
54 let toplevel = file.read_file()?;
55 let avif_chunk = find_chunk(
56 &toplevel,
57 &|c: &Chunk<DataRef>| {
58 let b = c.bytes(file.bytes());
59 &c.id == b"strd" && &b[..4] == b"AVIF"
60 },
61 ).unwrap();
62 let avif_chunk = avif_chunk.to_owned(file.bytes());
63 let avif_chunk = Entry::Chunk(avif_chunk);
64 let name_chunk = find_chunk(
65 &toplevel,
66 &|c: &Chunk<DataRef>| {
67 let b = c.bytes(file.bytes());
68 &c.id == b"strn" && &b[..4] == b"FUJI"
69 },
70 ).unwrap();
71 let name_chunk = name_chunk.to_owned(file.bytes());
72 let name_chunk = Entry::Chunk(name_chunk);
73
74
75 let file = RiffFile::open(&filename_base)?;
76 let toplevel = file.read_file()?.to_owned(file.bytes());
77
78 let new_toplevel = walk(toplevel, &|e| match e {
79 Entry::List(l) if &l.list_type == b"strl" => {
80 let mut l = l.clone();
81 let avif_chunk = avif_chunk.clone();
82 let position = l.children.iter().position(|e| match e {
83 Entry::Chunk(c) if &c.id == b"strd" => true,
84 _ => false,
85 });
86 match position {
87 Some(p) => {
88 l.children[p] = avif_chunk;
89 },
90 None => {
91 let pos = l.children.iter().position(|e| match e {
92 Entry::Chunk(c) if &c.id == b"strf" => true,
93 _ => false,
94 });
95 let pos = pos.map(|i| i + 1).unwrap_or(l.children.len());
96 l.children.insert(pos, avif_chunk);
97 },
98 };
99 let name_chunk = name_chunk.clone();
100 let position = l.children.iter().position(|e| match e {
101 Entry::Chunk(c) if &c.id == b"strn" => true,
102 _ => false,
103 });
104 match position {
105 Some(p) => {
106 l.children[p] = name_chunk;
107 },
108 None => {
109 let pos = l.children.iter().position(|e| match e {
110 Entry::Chunk(c) if &c.id == b"strd" => true,
111 _ => false,
112 });
113 let pos = pos.map(|i| i + 1).unwrap_or(l.children.len());
114 l.children.insert(pos, name_chunk);
115 },
116 };
117 Entry::List(l)
118 },
119 other => other,
120 });
121
122 let mut outfile = File::create(&filename_new)?;
123
124 new_toplevel.write(&mut outfile)?;
125
126 Ok(())
127}
Sourcepub fn read_file(&self) -> Result<Entry<DataRef>>
pub fn read_file(&self) -> Result<Entry<DataRef>>
Examples found in repository?
examples/view.rs (line 23)
10fn main() -> Result<()> {
11 if env::args().len() < 2 {
12 println!("Usage: view [filename]");
13 exit(-1);
14 }
15
16 let filename = env::args().nth(1).unwrap();
17
18 let file = RiffFile::open(&filename)?;
19
20 println!("File type: {}", format_fourcc(file.file_type()));
21 println!("File size: {}", file.file_size());
22
23 show_entry(&file.read_file()?, 0, file.bytes())?;
24 Ok(())
25}
More examples
examples/copy.rs (line 23)
11fn main() -> Result<()> {
12 if env::args().len() < 2 {
13 println!("Usage: copy [source] [desy]");
14 exit(-1);
15 }
16
17 let filename_src = env::args().nth(1).unwrap();
18 let filename_dst = env::args().nth(2).unwrap();
19
20 let file = RiffFile::open(&filename_src)?;
21 let mut outfile = File::create(&filename_dst)?;
22
23 let toplevel = file.read_file()?;
24 toplevel.to_owned(file.bytes()).write(&mut outfile)?;
25
26 Ok(())
27}
examples/copy_metadata.rs (line 54)
43fn main() -> Result<()> {
44 if env::args().len() < 2 {
45 println!("Usage: copy [source] [desy]");
46 exit(-1);
47 }
48
49 let filename_src = env::args().nth(1).unwrap();
50 let filename_base = env::args().nth(2).unwrap();
51 let filename_new = env::args().nth(3).unwrap();
52
53 let file = RiffFile::open(&filename_src)?;
54 let toplevel = file.read_file()?;
55 let avif_chunk = find_chunk(
56 &toplevel,
57 &|c: &Chunk<DataRef>| {
58 let b = c.bytes(file.bytes());
59 &c.id == b"strd" && &b[..4] == b"AVIF"
60 },
61 ).unwrap();
62 let avif_chunk = avif_chunk.to_owned(file.bytes());
63 let avif_chunk = Entry::Chunk(avif_chunk);
64 let name_chunk = find_chunk(
65 &toplevel,
66 &|c: &Chunk<DataRef>| {
67 let b = c.bytes(file.bytes());
68 &c.id == b"strn" && &b[..4] == b"FUJI"
69 },
70 ).unwrap();
71 let name_chunk = name_chunk.to_owned(file.bytes());
72 let name_chunk = Entry::Chunk(name_chunk);
73
74
75 let file = RiffFile::open(&filename_base)?;
76 let toplevel = file.read_file()?.to_owned(file.bytes());
77
78 let new_toplevel = walk(toplevel, &|e| match e {
79 Entry::List(l) if &l.list_type == b"strl" => {
80 let mut l = l.clone();
81 let avif_chunk = avif_chunk.clone();
82 let position = l.children.iter().position(|e| match e {
83 Entry::Chunk(c) if &c.id == b"strd" => true,
84 _ => false,
85 });
86 match position {
87 Some(p) => {
88 l.children[p] = avif_chunk;
89 },
90 None => {
91 let pos = l.children.iter().position(|e| match e {
92 Entry::Chunk(c) if &c.id == b"strf" => true,
93 _ => false,
94 });
95 let pos = pos.map(|i| i + 1).unwrap_or(l.children.len());
96 l.children.insert(pos, avif_chunk);
97 },
98 };
99 let name_chunk = name_chunk.clone();
100 let position = l.children.iter().position(|e| match e {
101 Entry::Chunk(c) if &c.id == b"strn" => true,
102 _ => false,
103 });
104 match position {
105 Some(p) => {
106 l.children[p] = name_chunk;
107 },
108 None => {
109 let pos = l.children.iter().position(|e| match e {
110 Entry::Chunk(c) if &c.id == b"strd" => true,
111 _ => false,
112 });
113 let pos = pos.map(|i| i + 1).unwrap_or(l.children.len());
114 l.children.insert(pos, name_chunk);
115 },
116 };
117 Entry::List(l)
118 },
119 other => other,
120 });
121
122 let mut outfile = File::create(&filename_new)?;
123
124 new_toplevel.write(&mut outfile)?;
125
126 Ok(())
127}
Auto Trait Implementations§
impl Freeze for RiffFile
impl RefUnwindSafe for RiffFile
impl Send for RiffFile
impl Sync for RiffFile
impl Unpin for RiffFile
impl UnwindSafe for RiffFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more