mf_file/
lib.rs

1pub mod document;
2pub mod error;
3pub mod history;
4pub mod record;
5pub mod zipdoc;
6pub use error::{FileError, Result};
7pub use record::{Writer, Reader, Iter, HEADER_LEN, REC_HDR};
8pub use document::{
9    DocumentWriter, DocumentReader, SegmentType, Directory, SegmentEntry,
10};
11pub use history::{TypeWrapper, encode_history_frames, decode_history_frames};
12pub use zipdoc::{
13    ZipDocumentWriter, ZipDocumentReader, MmapConfig, MmapStats,
14    ZipStreamReader, FileSizeCategory, ProcessingStrategy, FileInfo,
15    formats::strategy::{
16        SnapshotFormat, export_zip_with_format, import_zip_with_format,
17        export_plugin_states_only, import_plugin_states_only,
18        has_plugin_states, list_zip_plugins,
19    },
20};
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25    use tempfile::tempdir;
26
27    #[test]
28    fn roundtrip() -> Result<()> {
29        let dir = tempdir().unwrap();
30        let path = dir.path().join("data.mff");
31
32        let mut w = Writer::create(&path, 64 * 1024 * 1024)?;
33        let off1 = w.append(b"hello")?;
34        let off2 = w.append(b"world")?;
35        let big = vec![42u8; 128 * 1024];
36        let off3 = w.append(&big)?;
37        w.flush()?;
38
39        assert!(off2 > off1 && off3 > off2);
40
41        let r = Reader::open(&path)?;
42        assert_eq!(r.get_at(off1)?, b"hello");
43        assert_eq!(r.get_at(off2)?, b"world");
44        assert_eq!(r.get_at(off3)?, &big[..]);
45        assert_eq!(r.iter().count(), 3);
46
47        drop(w);
48        let mut w2 = Writer::create(&path, 64 * 1024 * 1024)?;
49        let off4 = w2.append(b"!")?;
50        w2.flush()?;
51
52        let r2 = Reader::open(&path)?;
53        assert_eq!(r2.get_at(off4)?, b"!");
54        Ok(())
55    }
56}
57
58// moved implementations to modules: document.rs, history.rs, zipdoc.rs