Get the full path for a given address, creating parent directories if needed Path structure: store/XX/YY/ZZ/remaining_hex where XX, YY, ZZ are the first 6 hex characters of the hash
(addr: &Address)
| 68 | /// Path structure: store/XX/YY/ZZ/remaining_hex |
| 69 | /// where XX, YY, ZZ are the first 6 hex characters of the hash |
| 70 | fn store_path(addr: &Address) -> StoreResult<PathBuf> { |
| 71 | let store = Self::store_dir()?; |
| 72 | let hex = addr.hex(); |
| 73 | let dir1 = &hex[0..2]; |
| 74 | let dir2 = &hex[2..4]; |
| 75 | let dir3 = &hex[4..6]; |
| 76 | let file = &hex[6..]; |
| 77 | let path = store.join(dir1).join(dir2).join(dir3); |
| 78 | if !path.exists() { |
| 79 | fs::create_dir_all(&path)?; |
| 80 | } |
| 81 | |
| 82 | Ok(path.join(file)) |
| 83 | } |
| 84 | |
| 85 | /// Write bytes to the store and return their address (blake3 hash) |
| 86 | pub fn write(bytes: &[u8]) -> StoreResult<Address> { |