Read the fanout table
@@ -7,6 +7,7 @@ pub mod index {
const V2_SIGNATURE: &'static [u8] = b"\xfftOc";
const FOOTER_LEN: usize = 20;
const N32_SIZE: usize = 4;
+ const FAN_LEN: usize = 256;
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
pub enum Kind {
@@ -25,6 +26,7 @@ pub mod index {
kind: Kind,
version: u32,
len: usize,
+ _fan: [u32; FAN_LEN],
}
impl File {
@@ -42,10 +44,10 @@ pub mod index {
let data = FileBuffer::open(path)
.with_context(|_| format!("Could not map file at '{}'", path.display()))?;
let idx_len = data.len();
- if idx_len < V2_SIGNATURE.len() + FOOTER_LEN {
+ if idx_len < FAN_LEN * N32_SIZE + FOOTER_LEN {
bail!("Pack index is truncated and not even empty");
}
- let (kind, version) = {
+ let (kind, version, fan) = {
let (kind, d) = {
let (sig, d) = data.split_at(V2_SIGNATURE.len());
let kind = if sig == V2_SIGNATURE {
@@ -67,14 +69,26 @@ pub mod index {
}
(v, d)
};
- (kind, version)
+ let (fan, bytes_read) = read_fan(d);
+ let (_, d) = d.split_at(bytes_read);
+
+ (kind, version, fan)
};
Ok(File {
_data: data,
kind,
len: 0,
version,
+ _fan: fan,
})
}
}
+
+ fn read_fan(d: &[u8]) -> ([u32; FAN_LEN], usize) {
+ let mut fan = [0; FAN_LEN];
+ for (c, f) in d.chunks(N32_SIZE).zip(fan.iter_mut()) {
+ *f = BigEndian::read_u32(c);
+ }
+ (fan, FAN_LEN * N32_SIZE)
+ }
}
