1pub mod concat;
5pub mod datatypes;
6pub mod format;
7pub(crate) mod io;
8pub mod reader;
9pub mod testing;
10pub mod version;
11pub mod versions;
12pub mod writer;
13
14#[cfg(test)]
15mod compatibility_tests;
16
17pub use io::LanceEncodingsIo;
18
19use format::MAGIC;
20use lance_core::{Error, Result};
21use lance_io::object_store::ObjectStore;
22use object_store::path::Path;
23use version::ConcreteFileVersion;
24
25pub async fn determine_file_version(
26 store: &ObjectStore,
27 path: &Path,
28 known_size: Option<usize>,
29) -> Result<ConcreteFileVersion> {
30 let size = match known_size {
31 None => usize::try_from(store.size(path).await?).map_err(|_| {
32 Error::invalid_input(format!("file {} is too large for this platform", path))
33 })?,
34 Some(size) => size,
35 };
36 if size < 8 {
37 return Err(Error::invalid_input_source(
38 format!(
39 "the file {} does not appear to be a lance file (too small)",
40 path
41 )
42 .into(),
43 ));
44 }
45 let reader = store.open_with_size(path, size).await?;
46 let footer = reader.get_range((size - 8)..size).await?;
47 if &footer[4..] != MAGIC {
48 return Err(Error::invalid_input_source(
49 format!(
50 "the file {} does not appear to be a lance file (magic mismatch)",
51 path
52 )
53 .into(),
54 ));
55 }
56 let major_version = u16::from_le_bytes([footer[0], footer[1]]);
57 let minor_version = u16::from_le_bytes([footer[2], footer[3]]);
58
59 ConcreteFileVersion::from_footer_numbers(major_version, minor_version)
60}