1 //! Blocking `pxar` format handling.
5 use std
::task
::{Context, Poll}
;
7 use crate::decoder
::{self, SeqRead}
;
8 use crate::util
::poll_result_once
;
11 /// Blocking `pxar` decoder.
13 /// This is the blocking I/O version of the `pxar` decoder. This will *not* work with an
14 /// asynchronous I/O object. I/O must always return `Poll::Ready`.
16 /// Attempting to use a `Waker` from this context *will* `panic!`
18 /// If you need to use asynchronous I/O, use `aio::Decoder`.
20 pub struct Decoder
<T
> {
21 inner
: decoder
::DecoderImpl
<T
>,
24 impl<T
: io
::Read
> Decoder
<T
> {
25 /// Decode a `pxar` archive from a regular `std::io::Read` input.
27 pub fn from_std(input
: T
) -> io
::Result
<Decoder
<StandardReader
<T
>>> {
28 Decoder
::new(StandardReader
::new(input
))
32 impl<T
: SeqRead
> Decoder
<T
> {
33 /// Create a *blocking* decoder from an input implementing our internal read interface.
35 /// Note that the `input`'s `SeqRead` implementation must always return `Poll::Ready` and is
36 /// not allowed to use the `Waker`, as this will cause a `panic!`.
37 pub fn new(input
: T
) -> io
::Result
<Self> {
39 inner
: poll_result_once(decoder
::DecoderImpl
::new(input
))?
,
43 /// Internal helper for `Accessor`. In this case we have the low-level state machine, and the
44 /// layer "above" the `Accessor` propagates the actual type (sync vs async).
45 pub(crate) fn from_impl(inner
: decoder
::DecoderImpl
<T
>) -> Self {
49 /// If this is a directory entry, get the next item inside the directory.
50 pub fn next(&mut self) -> Option
<io
::Result
<Entry
>> {
51 poll_result_once(self.inner
.next_do()).transpose()
55 impl<T
: SeqRead
> Iterator
for Decoder
<T
> {
56 type Item
= io
::Result
<Entry
>;
58 fn next(&mut self) -> Option
<Self::Item
> {
63 /// Pxar decoder read adapter for `std::io::Read`.
64 pub struct StandardReader
<T
> {
68 impl<T
: io
::Read
> StandardReader
<T
> {
69 pub fn new(inner
: T
) -> Self {
74 impl<T
: io
::Read
> SeqRead
for StandardReader
<T
> {
79 ) -> Poll
<io
::Result
<usize>> {
80 Poll
::Ready(unsafe { self.get_unchecked_mut() }
.inner
.read(buf
))