Skip to main content

hadris_cd/
lib.rs

1//! # Hadris CD
2//!
3//! A Rust library for creating hybrid ISO+UDF optical disc images.
4//!
5//! ## Overview
6//!
7//! This crate creates "UDF Bridge" format images that contain both
8//! ISO 9660 and UDF filesystems. This provides maximum compatibility:
9//! - Legacy systems read ISO 9660
10//! - Modern systems read UDF
11//! - **Both filesystems share the same file data on disk**
12//!
13//! ## Quick Start
14//!
15//! ```rust
16//! use hadris_cd::{CdWriter, CdOptions, FileTree, FileEntry};
17//! # use std::io::Cursor;
18//!
19//! // Create a file tree
20//! let mut tree = FileTree::new();
21//! tree.add_file(FileEntry::from_buffer("readme.txt", b"Hello, World!".to_vec()));
22//!
23//! // Create the hybrid image
24//! # // Use a Cursor for the doctest instead of a real file
25//! # let buffer = vec![0u8; 2 * 1024 * 1024]; // 2MB buffer
26//! # let file = Cursor::new(buffer);
27//! let options = CdOptions::with_volume_id("MY_DISC")
28//!     .with_joliet();
29//!
30//! CdWriter::new(file, options)
31//!     .write(tree)
32//!     .unwrap();
33//! ```
34//!
35//! ## Disk Layout
36//!
37//! The UDF Bridge format interleaves ISO 9660 and UDF structures:
38//!
39//! ```text
40//! Sector 0-15:    System area (boot code, partition tables)
41//! Sector 16-...:  ISO 9660 Volume Descriptors
42//! Sector 17-19:   UDF Volume Recognition Sequence (BEA01, NSR02, TEA01)
43//! Sector 256:     UDF Anchor Volume Descriptor Pointer
44//! Sector 257+:    UDF Volume Descriptor Sequence
45//! File data:      Shared between ISO and UDF (both point to same sectors)
46//! ```
47//!
48//! ## Features
49//!
50//! - ISO 9660 with Joliet (Windows long filenames) and Rock Ridge (POSIX)
51//! - UDF 1.02/1.50/2.00+ support
52//! - El-Torito bootable images
53//! - Hybrid MBR+GPT for USB booting
54
55#![allow(async_fn_in_trait)]
56
57// ---------------------------------------------------------------------------
58// Shared types (compiled once)
59// ---------------------------------------------------------------------------
60
61pub mod error;
62pub mod layout;
63pub mod options;
64pub mod tree;
65
66// ---------------------------------------------------------------------------
67// Sync module
68// ---------------------------------------------------------------------------
69
70#[cfg(feature = "sync")]
71#[path = ""]
72pub mod sync {
73    pub use hadris_io::SeekFrom;
74    pub use hadris_io::sync::{Read, Seek, Write};
75
76    macro_rules! io_transform {
77        ($($item:tt)*) => { hadris_macros::strip_async!{ $($item)* } };
78    }
79
80    macro_rules! sync_only {
81        ($($item:tt)*) => { $($item)* };
82    }
83
84    macro_rules! async_only {
85        ($($item:tt)*) => {};
86    }
87
88    #[path = "."]
89    mod __inner {
90        pub mod writer;
91    }
92    pub use __inner::*;
93
94    // Convenience re-exports
95    pub use __inner::writer::CdWriter;
96}
97
98// ---------------------------------------------------------------------------
99// Async module
100// ---------------------------------------------------------------------------
101
102#[cfg(feature = "async")]
103#[path = ""]
104pub mod r#async {
105    pub use hadris_io::SeekFrom;
106    pub use hadris_io::r#async::{Read, Seek, Write};
107
108    macro_rules! io_transform {
109        ($($item:tt)*) => { $($item)* };
110    }
111
112    macro_rules! sync_only {
113        ($($item:tt)*) => {};
114    }
115
116    macro_rules! async_only {
117        ($($item:tt)*) => { $($item)* };
118    }
119
120    #[path = "."]
121    mod __inner {
122        pub mod writer;
123    }
124    pub use __inner::*;
125}
126
127// ---------------------------------------------------------------------------
128// Default re-exports for backwards compatibility (sync)
129// ---------------------------------------------------------------------------
130
131#[cfg(feature = "sync")]
132pub use sync::*;
133
134// Re-exports from shared types
135pub use error::{CdError, CdResult};
136pub use layout::{LayoutInfo, LayoutManager};
137pub use options::{CdOptions, IsoOptions, UdfOptions};
138pub use tree::{Directory, FileData, FileEntry, FileExtent, FileTree};