1pub mod datatypes;
5pub mod format;
6pub mod page_table;
7pub mod reader;
8pub mod v2;
9pub mod writer;
10
11use format::MAGIC;
12pub use lance_encoding::version;
13
14use lance_core::{Error, Result};
15use lance_encoding::version::LanceFileVersion;
16use lance_io::object_store::ObjectStore;
17use object_store::path::Path;
18use snafu::location;
19
20pub async fn determine_file_version(
21 store: &ObjectStore,
22 path: &Path,
23 known_size: Option<usize>,
24) -> Result<LanceFileVersion> {
25 let size = match known_size {
26 None => store.size(path).await.unwrap(),
27 Some(size) => size,
28 };
29 if size < 8 {
30 return Err(Error::InvalidInput {
31 source: format!(
32 "the file {} does not appear to be a lance file (too small)",
33 path
34 )
35 .into(),
36 location: location!(),
37 });
38 }
39 let reader = store.open_with_size(path, size).await?;
40 let footer = reader.get_range((size - 8)..size).await?;
41 if &footer[4..] != MAGIC {
42 return Err(Error::InvalidInput {
43 source: format!(
44 "the file {} does not appear to be a lance file (magic mismatch)",
45 path
46 )
47 .into(),
48 location: location!(),
49 });
50 }
51 let major_version = u16::from_le_bytes([footer[0], footer[1]]);
52 let minor_version = u16::from_le_bytes([footer[2], footer[3]]);
53
54 LanceFileVersion::try_from_major_minor(major_version as u32, minor_version as u32)
55}