use std::mem;
use std::path::PathBuf;
use super::*;
#[derive(Debug, Args)]
pub struct GetSnapshotBlock {
#[arg(long)]
snapshot_id: String,
#[arg(long)]
block_index: i32,
#[arg(long)]
block_token: String,
outfile: PathBuf,
}
impl GetSnapshotBlock {
pub(crate) async fn execute(self, config: &Config) -> EbsResult {
let mut block = config
.ebs()
.get_snapshot_block()
.snapshot_id(self.snapshot_id)
.block_index(self.block_index)
.block_token(self.block_token)
.send()
.await?;
let contents = mem::take(&mut block.block_data)
.collect()
.await
.map(|bytes| bytes.into_bytes())
.map_err(ebs::error::BuildError::other)?;
tokio::fs::write(self.outfile, contents)
.await
.map_err(ebs::error::BuildError::other)?;
Ok(Box::new(block))
}
}