1
Fork 0

PR feedback

This commit is contained in:
Ben Kimock 2024-05-21 20:12:07 -04:00
parent 95150d7246
commit c3a606237d
10 changed files with 27 additions and 20 deletions

View file

@ -17,7 +17,7 @@ use crate::int_overflow::DebugStrictAdd;
pub type FileEncodeResult = Result<usize, (PathBuf, io::Error)>;
const FOOTER: &[u8] = b"rust-end-file";
pub const MAGIC_END_BYTES: &[u8] = b"rust-end-file";
/// The size of the buffer in `FileEncoder`.
const BUF_SIZE: usize = 8192;
@ -183,7 +183,7 @@ impl FileEncoder {
}
pub fn finish(&mut self) -> FileEncodeResult {
self.write_all(FOOTER);
self.write_all(MAGIC_END_BYTES);
self.flush();
#[cfg(debug_assertions)]
{
@ -264,10 +264,10 @@ pub struct MemDecoder<'a> {
impl<'a> MemDecoder<'a> {
#[inline]
pub fn new(data: &'a [u8], position: usize) -> Option<MemDecoder<'a>> {
let data = data.strip_suffix(FOOTER)?;
pub fn new(data: &'a [u8], position: usize) -> Result<MemDecoder<'a>, ()> {
let data = data.strip_suffix(MAGIC_END_BYTES).ok_or(())?;
let Range { start, end } = data.as_ptr_range();
Some(MemDecoder { start, current: data[position..].as_ptr(), end, _marker: PhantomData })
Ok(MemDecoder { start, current: data[position..].as_ptr(), end, _marker: PhantomData })
}
#[inline]