fix alignment of tables
This commit is contained in:
1 parent
13ee0dcf01
commit
076c60658d
2 files changed
+17
-16
No files matched your search
+16
-15
@@ -64,16 +64,21 @@ impl Database {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
pub fn export(self, path: &Path) -> std::io::Result<()> {
|
pub fn export(self, path: &Path) -> std::io::Result<()> {
|
||||||
// 1) Reserve header page
|
|
||||||
let mut f = File::create(path)?;
|
let mut f = File::create(path)?;
|
||||||
f.write_all(&vec![0u8; PAGE_SIZE as usize])?;
|
// reserve the file header space
|
||||||
|
// tables begin at 28
|
||||||
|
f.write_all(&vec![0u8; 28 as usize])?;
|
||||||
|
|
||||||
let (table, pages) = Table::from_rows(PageType::Tracks, 1, PAGE_SIZE, self.tracks.values().cloned().take(1).map(Row::Track)).unwrap();
|
// tables start here
|
||||||
|
let (tracks, tracks_pages) = Table::from_rows(PageType::Tracks, 1, PAGE_SIZE, self.tracks.values().cloned().take(2).map(Row::Track)).unwrap();
|
||||||
|
// f.seek(SeekFrom::Start(0x1c)).unwrap();
|
||||||
|
println!("Writing table at {:?}", f.stream_position());
|
||||||
|
tracks.write_le(&mut f).unwrap();
|
||||||
|
|
||||||
println!("{:?}", table);
|
f.seek(SeekFrom::Start(4096)).unwrap();
|
||||||
println!("{:?}", pages);
|
println!("Writing tracks_pages at {:?}", f.stream_position());
|
||||||
table.write_le(&mut f).unwrap();
|
tracks_pages.write_le_args(&mut f, (PAGE_SIZE.into(),)).unwrap();
|
||||||
pages.write_le_args(&mut f, (PAGE_SIZE.into(),)).unwrap();
|
println!("{:?}", f.stream_position());
|
||||||
|
|
||||||
// page is somehow getting zeroed when ... writing? reading??
|
// page is somehow getting zeroed when ... writing? reading??
|
||||||
// validate it by writing and reading it back
|
// validate it by writing and reading it back
|
||||||
@@ -100,9 +105,9 @@ impl Database {
|
|||||||
let header = Header {
|
let header = Header {
|
||||||
// fill other required fields in your crate
|
// fill other required fields in your crate
|
||||||
sequence: 0, // or previous+1
|
sequence: 0, // or previous+1
|
||||||
next_unused_page: PageIndex(pages.len() as u32 + 1),
|
next_unused_page: PageIndex(tracks_pages.len() as u32 + 1),
|
||||||
tables: vec![
|
tables: vec![
|
||||||
table,
|
tracks,
|
||||||
// Table { page_type: PageType::PlaylistTree, first_page: PageIndex(tree_first), last_page: PageIndex(tree_last), empty_candidate: 0, /* … */ },
|
// Table { page_type: PageType::PlaylistTree, first_page: PageIndex(tree_first), last_page: PageIndex(tree_last), empty_candidate: 0, /* … */ },
|
||||||
// Table { page_type: PageType::PlaylistEntries, first_page: PageIndex(entries_first), last_page: PageIndex(entries_last), empty_candidate: 0, /* … */ },
|
// Table { page_type: PageType::PlaylistEntries, first_page: PageIndex(entries_first), last_page: PageIndex(entries_last), empty_candidate: 0, /* … */ },
|
||||||
// Table { page_type: PageType::Artwork, first_page: PageIndex(art_first), last_page: PageIndex(art_last), empty_candidate: 0, /* … */ },
|
// Table { page_type: PageType::Artwork, first_page: PageIndex(art_first), last_page: PageIndex(art_last), empty_candidate: 0, /* … */ },
|
||||||
@@ -110,14 +115,10 @@ impl Database {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write header at offset 0 and pad to one page
|
|
||||||
f.seek(SeekFrom::Start(0))?;
|
f.seek(SeekFrom::Start(0))?;
|
||||||
|
println!("Writing header at {:?}", f.stream_position());
|
||||||
header.write_le(&mut f).unwrap();
|
header.write_le(&mut f).unwrap();
|
||||||
// pad residual of page 0 if BinWrite didn’t fill it:
|
|
||||||
let pos = f.stream_position()?;
|
|
||||||
if pos < PAGE_SIZE as u64 {
|
|
||||||
f.write_all(&vec![0u8; (PAGE_SIZE as u64 - pos) as usize])?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"path": "C:\\Users\\ntr\\code\\rekordcrate",
|
"path": "C:\\Users\\ntr\\code\\rekordcrate",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "/home/ntr/code/rekordcrate"
|
"path": "/Users/nathanrashleigh/code/code/rekordcrate"
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"settings":
|
"settings":
|
||||||
|
|||||||
Reference in new issue
Block a user