Actually comment ogg_pager

Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
Serial 2021-06-29 15:02:39 -04:00
parent fb531877ac
commit 67d0e75655
4 changed files with 11 additions and 2 deletions

2
ogg_pager/Cargo.lock generated
View file

@ -10,7 +10,7 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "ogg_pager" name = "ogg_pager"
version = "0.1.4" version = "0.1.5"
dependencies = [ dependencies = [
"byteorder", "byteorder",
] ]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ogg_pager" name = "ogg_pager"
version = "0.1.4" version = "0.1.5"
authors = ["Serial <69764315+Serial-ATA@users.noreply.github.com>"] authors = ["Serial <69764315+Serial-ATA@users.noreply.github.com>"]
edition = "2018" edition = "2018"
repository = "https://github.com/Serial-ATA/lofty-rs" repository = "https://github.com/Serial-ATA/lofty-rs"

View file

@ -5,9 +5,13 @@ pub type Result<T> = std::result::Result<T, PageError>;
#[derive(Debug)] #[derive(Debug)]
pub enum PageError { pub enum PageError {
/// The reader contains a page with a nonzero version
InvalidVersion, InvalidVersion,
/// The reader contains a page with a segment count < 1
BadSegmentCount, BadSegmentCount,
/// The reader contains a page without a magic signature (OggS)
MissingMagic, MissingMagic,
/// Any std::io::Error
Io(std::io::Error), Io(std::io::Error),
} }

View file

@ -21,6 +21,7 @@ pub struct Page {
} }
impl Page { impl Page {
/// Convert the Page to Vec<u8> for writing
pub fn as_bytes(&self) -> Vec<u8> { pub fn as_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new(); let mut bytes = Vec::new();
let segments = self.segments(); let segments = self.segments();
@ -40,10 +41,12 @@ impl Page {
bytes bytes
} }
/// Returns the Page's segment table as Vec<u8>
pub fn segments(&self) -> Vec<u8> { pub fn segments(&self) -> Vec<u8> {
segments(&*self.content) segments(&*self.content)
} }
/// Attempts to get a Page from a reader
pub fn read<V>(mut data: V) -> Result<Self> pub fn read<V>(mut data: V) -> Result<Self>
where where
V: Read + Seek, V: Read + Seek,
@ -97,10 +100,12 @@ impl Page {
}) })
} }
/// Generates the CRC checksum of the page
pub fn gen_crc(&mut self) { pub fn gen_crc(&mut self) {
self.checksum = crc::crc32(&*self.as_bytes()); self.checksum = crc::crc32(&*self.as_bytes());
} }
/// Extends the Page's content, returning another Page if too much data was provided
pub fn extend(&mut self, content: &[u8]) -> Option<Page> { pub fn extend(&mut self, content: &[u8]) -> Option<Page> {
let self_len = self.content.len(); let self_len = self.content.len();
let content_len = content.len(); let content_len = content.len();