Skip to content

Commit c1247dc

Browse files
committed
docs: readme complete, basic.rs
1 parent 198be57 commit c1247dc

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
For projects that use large amounts of duplicate files
44

5+
## Using
6+
7+
### Terminology
8+
9+
- Repo: The storage location of all uploaded chunks, artifacts, and manifests. Commonly used by the distributer of directories.
10+
- Store: The storage location of all downloaded chunks and manifests, alongside the built artifacts. Commonly used by the downloader of directories.
11+
- Manifest: A list of every file's relation to a chunk used to recreate the Artifact.
12+
- Artifact: The actual target directory.
13+
- Chunk: A raw deduplicated file.
14+
15+
Please note: There is minor differences between implementation depending on whether they are in relation to the Store or Repo.
16+
17+
### Examples
18+
19+
For further examples please check [the examples in the source tree.](https://github.com/TimelessOS/LCAS/tree/main/examples)
20+
521
## Contributing
622

723
### TODO
@@ -10,4 +26,4 @@ For projects that use large amounts of duplicate files
1026
- [ ] Error handling (Should be propogated upwards)
1127
- [ ] Proper tests
1228
- [ ] Proper/Better documentation
13-
- [ ] Cross platform
29+
- [ ] Windows Support (UNIX-Like only)

examples/basic.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::io;
2+
use std::path::absolute;
3+
use std::{fs, path::Path};
4+
5+
use lcas::{build, create_repo, create_store, install_artifact};
6+
7+
fn main() -> Result<(), String> {
8+
// Helper variables
9+
// `input_dir` is the artifact, likely produced by a build system etc. This is what we want to "transmit".
10+
let input_dir = absolute(Path::new("./example_dir")).unwrap();
11+
// `repo_dir` is the Repo's contained directory, and should be hosted on a web server, as a directory, etc.
12+
let repo_dir = absolute(Path::new("./example_repo")).unwrap();
13+
// `store_dir` is the local path for the local store, and will be where the Store is placed, and each artifact inside.
14+
let store_dir = absolute(Path::new("./example_store")).unwrap();
15+
16+
// Create an example repo and a store, *locally*
17+
create_repo(repo_dir.as_path())?;
18+
create_store(&store_dir)?;
19+
20+
// Create an example artifact
21+
fs::create_dir_all(Path::new("./example_dir/nested_dir/super_nested_dir")).unwrap();
22+
fs::write("./example_dir/a", "Wow a file").unwrap();
23+
fs::write("./example_dir/nested_dir/b", "Wow another file, shocking.").unwrap();
24+
fs::write(
25+
"./example_dir/nested_dir/super_nested_dir/c",
26+
"Nested nested nested file",
27+
)
28+
.unwrap();
29+
30+
// Compile the artifact into a manifest and chunks and store it
31+
build(
32+
input_dir.as_path(),
33+
repo_dir.as_path(),
34+
&"generic".to_string(),
35+
)
36+
.expect("Build Failure");
37+
38+
// Install the resulting manifest into an artifact in the `store_dir`
39+
install_artifact(&"generic".to_string(), store_dir.as_path(), &repo_dir);
40+
41+
Ok(())
42+
}

0 commit comments

Comments
 (0)