1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
//! ZboxFS is a zero-details, privacy-focused in-app file system. //! //! It keeps your app files securely, privately and reliably on underlying //! storages. By encapsulating files and directories into an encrypted //! repository, it provides a virtual file system and exclusive access to //! the authorised application. //! //! The most core parts of this module are [`Repo`] and [`File`], which provides //! most file system operations and file I/O. //! //! - [`Repo`] provides similar file system manipulation methods to [`std::fs`] //! - [`File`] provides similar file I/O methods to [`std::fs::File`] //! //! [`init_env`] initialises the environment and should be called once before //! any other methods provied by ZboxFS. //! //! After repository is opened by [`RepoOpener`], all of the other functions //! provided by ZboxFS will be thread-safe. //! //! # Examples //! //! Create and open a [`Repo`] using memory as underlying storage. //! //! ``` //! # #![allow(unused_mut, unused_variables)] //! use zbox::{init_env, RepoOpener}; //! //! // initialise zbox environment, called first //! init_env(); //! //! // create and open a repository //! let mut repo = RepoOpener::new() //! .create(true) //! .open("mem://my_repo", "your password") //! .unwrap(); //! ``` //! //! [`File`] content IO using [`Read`] and [`Write`] traits. //! //! ``` //! # use zbox::{init_env, RepoOpener}; //! use std::io::prelude::*; //! use std::io::{Seek, SeekFrom}; //! use zbox::OpenOptions; //! # init_env(); //! # let mut repo = RepoOpener::new() //! # .create(true) //! # .open("mem://foo", "pwd") //! # .unwrap(); //! //! // create and open a file for writing //! let mut file = OpenOptions::new() //! .create(true) //! .open(&mut repo, "/my_file.txt") //! .unwrap(); //! //! // use std::io::Write trait to write data into it //! file.write_all(b"Hello, world!").unwrap(); //! //! // finish writting to make a permanent content version //! file.finish().unwrap(); //! //! // read file content using std::io::Read trait //! let mut content = String::new(); //! file.seek(SeekFrom::Start(0)).unwrap(); //! file.read_to_string(&mut content).unwrap(); //! assert_eq!(content, "Hello, world!"); //! ``` //! //! Directory navigation can use [`Path`] and [`PathBuf`]. The path separator //! should always be "/", even on Windows. //! //! ``` //! # use zbox::{init_env, RepoOpener}; //! use std::path::Path; //! # init_env(); //! # let mut repo = RepoOpener::new() //! # .create(true) //! # .open("mem://foo", "pwd") //! # .unwrap(); //! //! let path = Path::new("/foo/bar"); //! repo.create_dir_all(&path).unwrap(); //! assert!(repo.is_dir(path.parent().unwrap()).is_ok()); //! ``` //! //! [`std::fs`]: https://doc.rust-lang.org/std/fs/index.html //! [`std::fs::File`]: https://doc.rust-lang.org/std/fs/struct.File.html //! [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html //! [`Write`]: https://doc.rust-lang.org/std/io/trait.Write.html //! [`Path`]: https://doc.rust-lang.org/std/path/struct.Path.html //! [`PathBuf`]: https://doc.rust-lang.org/std/path/struct.PathBuf.html //! [`init_env`]: fn.init_env.html //! [`Repo`]: struct.Repo.html //! [`File`]: struct.File.html //! [`RepoOpener`]: struct.RepoOpener.html extern crate bytes; #[macro_use] extern crate cfg_if; extern crate env_logger; extern crate linked_hash_map; #[macro_use] extern crate log; extern crate rmp_serde; extern crate serde; #[macro_use] extern crate serde_derive; macro_rules! map_io_err { ($x:expr) => { $x.map_err(|e| IoError::new(ErrorKind::Other, e.description())); }; } mod base; mod binding; mod content; mod error; mod file; mod fs; mod repo; mod trans; mod version; mod volume; pub use self::base::crypto::{Cipher, MemLimit, OpsLimit}; pub use self::base::init_env; pub use self::error::{Error, Result}; pub use self::file::{File, VersionReader}; pub use self::fs::fnode::{DirEntry, FileType, Metadata, Version}; pub use self::repo::{OpenOptions, Repo, RepoInfo, RepoOpener}; pub use self::trans::Eid; #[cfg(feature = "storage-faulty")] #[macro_use] extern crate lazy_static; #[cfg(any(feature = "storage-faulty", feature = "storage-zbox-faulty"))] pub use self::volume::FaultyController; #[cfg(feature = "storage-sqlite")] extern crate libsqlite3_sys; #[cfg(feature = "storage-redis")] extern crate redis; #[cfg(feature = "storage-zbox")] extern crate http; #[cfg(feature = "storage-zbox")] extern crate serde_json; #[cfg(feature = "storage-zbox-faulty")] #[macro_use] extern crate lazy_static; #[cfg(feature = "storage-zbox-native")] extern crate reqwest; #[cfg(feature = "storage-zbox-jni")] extern crate jni; #[cfg(feature = "storage-zbox-jni")] #[macro_use] extern crate lazy_static; #[cfg(target_os = "android")] extern crate android_logger; #[cfg(feature = "storage-zbox-wasm")] extern crate wasm_bindgen; #[cfg(feature = "storage-zbox-wasm")] extern crate js_sys; #[cfg(feature = "storage-zbox-wasm")] extern crate web_sys; #[cfg(feature = "storage-zbox-wasm")] extern crate wasm_logger;