proxmox-backup/src/tape/tape_read.rs

33 lines
935 B
Rust
Raw Normal View History

2020-12-05 09:54:38 +00:00
use std::io::Read;
/// Read trait for tape devices
///
/// Normal Read, but allows to query additional status flags.
pub trait TapeRead: Read {
/// Return true if there is an "INCOMPLETE" mark at EOF
///
/// Raises an error if you query this flag before reaching EOF.
fn is_incomplete(&self) -> Result<bool, std::io::Error>;
/// Return true if there is a file end marker before EOF
///
/// Raises an error if you query this flag before reaching EOF.
fn has_end_marker(&self) -> Result<bool, std::io::Error>;
}
2021-04-12 09:25:40 +00:00
#[derive(thiserror::Error, Debug)]
pub enum BlockReadError {
#[error("{0}")]
Error(#[from] std::io::Error),
#[error("end of file")]
2021-03-29 08:09:49 +00:00
EndOfFile,
2021-04-12 09:25:40 +00:00
#[error("end of data stream")]
2021-03-29 08:09:49 +00:00
EndOfStream,
}
2020-12-05 09:54:38 +00:00
2021-03-29 08:09:49 +00:00
/// Read streams of blocks
pub trait BlockRead {
/// Read the next block (whole buffer)
2021-04-12 09:25:40 +00:00
fn read_block(&mut self, buffer: &mut [u8]) -> Result<usize, BlockReadError>;
2020-12-05 09:54:38 +00:00
}