async_tar/
lib.rs

1//! A library for reading and writing TAR archives in an async fashion.
2//!
3//! This library provides utilities necessary to manage [TAR archives][1]
4//! abstracted over a reader or writer. Great strides are taken to ensure that
5//! an archive is never required to be fully resident in memory, and all objects
6//! provide largely a streaming interface to read bytes from.
7//!
8//! [1]: http://en.wikipedia.org/wiki/Tar_%28computing%29
9
10// More docs about the detailed tar format can also be found here:
11// http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5&manpath=FreeBSD+8-current
12
13// NB: some of the coding patterns and idioms here may seem a little strange.
14//     This is currently attempting to expose a super generic interface while
15//     also not forcing clients to codegen the entire crate each time they use
16//     it. To that end lots of work is done to ensure that concrete
17//     implementations are all found in this crate and the generic functions are
18//     all just super thin wrappers (e.g. easy to codegen).
19
20#![deny(missing_docs)]
21#![deny(clippy::all)]
22
23#[cfg(all(feature = "runtime-async-std", feature = "runtime-tokio"))]
24compile_error!(
25    "Features `runtime-async-std` and `runtime-tokio` are mutually exclusive. Please enable only one."
26);
27
28#[cfg(not(any(feature = "runtime-async-std", feature = "runtime-tokio")))]
29compile_error!("Either `runtime-async-std` or `runtime-tokio` feature must be enabled.");
30
31use std::io::Error;
32
33pub use crate::{
34    archive::{Archive, ArchiveBuilder, Entries},
35    builder::Builder,
36    entry::{Entry, Unpacked},
37    entry_type::EntryType,
38    header::{
39        GnuExtSparseHeader, GnuHeader, GnuSparseHeader, Header, HeaderMode, OldHeader, UstarHeader,
40    },
41    pax::{PaxExtension, PaxExtensions},
42};
43
44mod archive;
45mod builder;
46mod entry;
47mod entry_type;
48mod error;
49mod header;
50mod pax;
51
52#[cfg(test)]
53#[macro_use]
54extern crate static_assertions;
55
56fn other(msg: &str) -> Error {
57    Error::other(msg)
58}
59
60#[cfg(feature = "runtime-async-std")]
61pub(crate) async fn fs_canonicalize(
62    path: &async_std::path::Path,
63) -> async_std::io::Result<async_std::path::PathBuf> {
64    path.canonicalize().await
65}
66#[cfg(feature = "runtime-tokio")]
67pub(crate) async fn fs_canonicalize(
68    path: &std::path::Path,
69) -> tokio::io::Result<std::path::PathBuf> {
70    tokio::fs::canonicalize(path).await
71}
72
73#[cfg(feature = "runtime-async-std")]
74async fn symlink_metadata(
75    p: &async_std::path::Path,
76) -> async_std::io::Result<async_std::fs::Metadata> {
77    p.symlink_metadata().await
78}
79#[cfg(feature = "runtime-tokio")]
80async fn symlink_metadata(p: &std::path::Path) -> tokio::io::Result<std::fs::Metadata> {
81    tokio::fs::symlink_metadata(p).await
82}
83
84#[cfg(feature = "runtime-async-std")]
85async fn metadata(p: &async_std::path::Path) -> async_std::io::Result<async_std::fs::Metadata> {
86    p.metadata().await
87}
88#[cfg(feature = "runtime-tokio")]
89async fn metadata(p: &std::path::Path) -> tokio::io::Result<std::fs::Metadata> {
90    tokio::fs::metadata(p).await
91}