1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! Async archive reader abstraction layer.
//!
//! This module provides the [`AsyncArchiveReader`] trait, which defines the interface for
//! asynchronously reading entries from archive containers (ZIP files). It mirrors the synchronous
//! [`lib3mf_core::archive::ArchiveReader`] trait but with async methods.
//!
//! ## Design
//!
//! The trait abstracts over different async archive implementations, allowing the 3MF loader
//! to work with any async archive backend. Currently, [`AsyncZipArchive`] is the primary
//! implementation using the async-zip crate.
//!
//! ## Examples
//!
//! ```no_run
//! use lib3mf_async::archive::AsyncArchiveReader;
//! use lib3mf_async::zip::AsyncZipArchive;
//! use tokio::fs::File;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let file = File::open("model.3mf").await?;
//! let mut archive = AsyncZipArchive::new(file).await?;
//!
//! // Check if an entry exists
//! if archive.entry_exists("_rels/.rels").await {
//! // Read the entry
//! let data = archive.read_entry("_rels/.rels").await?;
//! println!("Read {} bytes", data.len());
//! }
//!
//! // List all entries
//! let entries = archive.list_entries().await?;
//! println!("Archive contains {} entries", entries.len());
//!
//! Ok(())
//! }
//! ```
//!
//! [`AsyncZipArchive`]: crate::zip::AsyncZipArchive
use async_trait;
use Result;
/// Trait for reading entries from an archive asynchronously.
///
/// This trait provides async methods for reading archive contents without blocking the executor.
/// It is analogous to [`lib3mf_core::archive::ArchiveReader`] but with async/await semantics.
///
/// # Trait Bounds
///
/// Implementors must be `Send + Sync` to allow the archive reader to be used across async task
/// boundaries. This is required because async functions may be sent between threads in the tokio
/// runtime.
///
/// # Implementors
///
/// - [`AsyncZipArchive`]: ZIP archive reader using async-zip
///
/// [`AsyncZipArchive`]: crate::zip::AsyncZipArchive