use std::io;
+#[cfg(feature = "tokio-fs")]
+use std::path::Path;
+
use crate::decoder::{self, SeqRead};
use crate::Entry;
}
#[cfg(feature = "futures-io")]
-impl<T: futures::io::AsyncRead> Decoder<T> {
+impl<T: futures::io::AsyncRead> Decoder<FuturesReader<T>> {
/// Decode a `pxar` archive from a `futures::io::AsyncRead` input.
#[inline]
- pub async fn from_futures(input: T) -> io::Result<Decoder<FuturesReader<T>>> {
+ pub async fn from_futures(input: T) -> io::Result<Self> {
Decoder::new(FuturesReader::new(input)).await
}
}
#[cfg(feature = "tokio-io")]
-impl<T: tokio::io::AsyncRead> Decoder<T> {
+impl<T: tokio::io::AsyncRead> Decoder<TokioReader<T>> {
/// Decode a `pxar` archive from a `tokio::io::AsyncRead` input.
#[inline]
- pub async fn from_tokio(input: T) -> io::Result<Decoder<TokioReader<T>>> {
+ pub async fn from_tokio(input: T) -> io::Result<Self> {
Decoder::new(TokioReader::new(input)).await
}
}
+#[cfg(feature = "tokio-fs")]
+impl Decoder<TokioReader<tokio::fs::File>> {
+ /// Decode a `pxar` archive from a `tokio::io::AsyncRead` input.
+ #[inline]
+ pub async fn open<P: AsRef<Path>>(path: P) -> io::Result<Self> {
+ Decoder::from_tokio(tokio::fs::File::open(path.as_ref()).await?).await
+ }
+}
+
impl<T: SeqRead> Decoder<T> {
/// Create an async decoder from an input implementing our internal read interface.
pub async fn new(input: T) -> io::Result<Self> {
//! Blocking `pxar` format handling.
use std::io;
+use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};
inner: decoder::DecoderImpl<T>,
}
-impl<T: io::Read> Decoder<T> {
+impl<T: io::Read> Decoder<StandardReader<T>> {
/// Decode a `pxar` archive from a regular `std::io::Read` input.
#[inline]
- pub fn from_std(input: T) -> io::Result<Decoder<StandardReader<T>>> {
+ pub fn from_std(input: T) -> io::Result<Self> {
Decoder::new(StandardReader::new(input))
}
}
+impl Decoder<StandardReader<std::fs::File>> {
+ /// Convenience shortcut for `File::open` followed by `Accessor::from_file`.
+ pub fn open<P: AsRef<Path>>(path: P) -> io::Result<Self> {
+ Self::from_std(std::fs::File::open(path.as_ref())?)
+ }
+}
+
impl<T: SeqRead> Decoder<T> {
/// Create a *blocking* decoder from an input implementing our internal read interface.
///