Struct bookfile::Book [−][src]
pub struct Book<R> { /* fields omitted */ }
Expand description
An interface for reading a Bookfile.
The Book
type represents a read-only Bookfile. Invividual chapters can
be read in their entirety, or incrementally using the Read
interface.
Seek
and read_at
/read_exact_at
are also provided, and work within the context of that chapter: the seek
offset is the offset within the chapter, and a read at the end of the
chapter will return EOF.
Implementations
pub fn chapter_reader<Id>(&self, index: Id) -> Result<BoundedReader<&File>> where
Id: Into<ChapterId>,
pub fn chapter_reader<Id>(&self, index: Id) -> Result<BoundedReader<&File>> where
Id: Into<ChapterId>,
Create a shared reader object.
This returns a BoundedReader that does not implement Seek
or Read
, only
read_at
and read_exact_at
This means it can be used via a shared reference.
If the Seek
and Read
traits are required, use exclusive_chapter_reader
instead.
Read all bytes in a chapter.
This is the same thing as calling chapter_reader
followed by
read_exact_at
.
Create a new Book from a stream.
This call will attempt to read the file header and table of contents. It may fail due to IO errors while reading, or invalid file data.
The stream must impl the Read
and Seek
traits (e.g. a File
).
Check whether a chapter exists.
For now, we assume chapter ids are unique. That’s dumb, and will be fixed in a future version.
pub fn exclusive_chapter_reader<Id>(
&mut self,
id: Id
) -> Result<BoundedReader<&mut R>> where
Id: Into<ChapterId>,
pub fn exclusive_chapter_reader<Id>(
&mut self,
id: Id
) -> Result<BoundedReader<&mut R>> where
Id: Into<ChapterId>,
Read a chapter, with seeking.
This returns a BoundedReader
that can read and seek within the chapter
(assuming the underlying Book implements Read + Seek
).
The Seek
and Read
traits require exclusive access. For a shared reader,
use chapter_reader
instead.
Read all bytes in a chapter.
This is the same thing as calling exclusive_chapter_reader
followed by read_to_end
. It can be used on anything that implements
Read + Seek
, but as a result it requires exclusive access via a
mutable reference.
Trait Implementations
Auto Trait Implementations
impl<R> RefUnwindSafe for Book<R> where
R: RefUnwindSafe,
impl<R> UnwindSafe for Book<R> where
R: UnwindSafe,