Skip to content

Commit 64c602e

Browse files
committed
fix data offset after conversion
1 parent ca41853 commit 64c602e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

fang-cli/src/actions/mst/convert.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,29 @@ pub fn convert_mst(opts: ConvertOpts) -> anyhow::Result<()> {
5454

5555
let mut content_offsets = Vec::new();
5656
for content_buf in content_bufs {
57-
let mut pos = out_file.seek(SeekFrom::Current(0))?;
57+
let mut pos = out_file.stream_position()?;
5858
if pos % 2048 > 0 {
5959
let padding = 2048 - pos % 2048;
6060
let padding = vec![0u8; padding as usize];
6161
out_file.write_all(&padding)?;
62-
pos = out_file.seek(SeekFrom::Current(0))?;
62+
pos = out_file.stream_position()?;
6363
}
6464

6565
content_offsets.push(pos);
6666
out_file.write_all(&content_buf)?;
6767
}
6868

69+
if let Some(min_data_offset) = content_offsets.iter().min() {
70+
out_file.seek(SeekFrom::Start(28))?;
71+
72+
let offset = *min_data_offset as u32;
73+
if mst.identifier.is_little() {
74+
out_file.write_all(&offset.to_le_bytes())?;
75+
} else {
76+
out_file.write_all(&offset.to_be_bytes())?;
77+
}
78+
}
79+
6980
for (pos, offset) in content_offset_offsets.borrow().iter().zip(content_offsets) {
7081
out_file.seek(SeekFrom::Start(*pos))?;
7182

0 commit comments

Comments
 (0)