summaryrefslogtreecommitdiff
path: root/src/cmd/chunkify.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-31 10:37:13 +0000
committerLars Wirzenius <liw@liw.fi>2021-12-31 10:37:13 +0000
commit4e0c91dcb2c9f0c362e579a8d0142936d413c235 (patch)
tree1ce0288f878cac71990bb01f358d6035f1626c92 /src/cmd/chunkify.rs
parent686e87981db210fa443404c8473dfe7a3f39b241 (diff)
parentacf1ba3f8f1492b961c9a6eb09eb93e882f5eb3f (diff)
downloadobnam2-4e0c91dcb2c9f0c362e579a8d0142936d413c235.tar.gz
Merge branch 'docs' into 'main'
docs: add documentation comments to crate Closes #151 See merge request obnam/obnam!200
Diffstat (limited to 'src/cmd/chunkify.rs')
-rw-r--r--src/cmd/chunkify.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/cmd/chunkify.rs b/src/cmd/chunkify.rs
index 79fbdea..e2ce05f 100644
--- a/src/cmd/chunkify.rs
+++ b/src/cmd/chunkify.rs
@@ -1,3 +1,5 @@
+//! The `chunkify` subcommand.
+
use crate::config::ClientConfig;
use crate::engine::Engine;
use crate::error::ObnamError;
@@ -15,18 +17,21 @@ use tokio::sync::mpsc;
// checksums.
const Q: usize = 8;
+/// Split files into chunks and show their metadata.
#[derive(Debug, StructOpt)]
pub struct Chunkify {
+ /// Names of files to split into chunks.
filenames: Vec<PathBuf>,
}
impl Chunkify {
+ /// Run the command.
pub fn run(&self, config: &ClientConfig) -> Result<(), ObnamError> {
let rt = Runtime::new()?;
rt.block_on(self.run_async(config))
}
- pub async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> {
+ async fn run_async(&self, config: &ClientConfig) -> Result<(), ObnamError> {
let mut q = WorkQueue::new(Q);
for filename in self.filenames.iter() {
tokio::spawn(split_file(
@@ -51,21 +56,21 @@ impl Chunkify {
}
#[derive(Debug, Clone)]
-pub struct Chunk {
+struct Chunk {
filename: PathBuf,
offset: u64,
data: Vec<u8>,
}
#[derive(Debug, Clone, Serialize)]
-pub struct Checksum {
+struct Checksum {
filename: PathBuf,
offset: u64,
pub len: u64,
checksum: String,
}
-pub async fn split_file(filename: PathBuf, chunk_size: usize, tx: mpsc::Sender<Chunk>) {
+async fn split_file(filename: PathBuf, chunk_size: usize, tx: mpsc::Sender<Chunk>) {
// println!("split_file {}", filename.display());
let mut file = BufReader::new(File::open(&*filename).await.unwrap());