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    #[allow(unused_macros)]
81    macro_rules! sync_only {
82        ($($item:tt)*) => { $($item)* };
83    }
84
85    #[allow(unused_macros)]
86    macro_rules! async_only {
87        ($($item:tt)*) => {};
88    }
89
90    #[path = "."]
91    mod __inner {
92        pub mod writer;
93    }
94    pub use __inner::*;
95
96    // Convenience re-exports
97    pub use __inner::writer::CdWriter;
98}
99
100// ---------------------------------------------------------------------------
101// Async module
102// ---------------------------------------------------------------------------
103
104#[cfg(feature = "async")]
105#[path = ""]
106pub mod r#async {
107    pub use hadris_io::SeekFrom;
108    pub use hadris_io::r#async::{Read, Seek, Write};
109
110    macro_rules! io_transform {
111        ($($item:tt)*) => { $($item)* };
112    }
113
114    #[allow(unused_macros)]
115    macro_rules! sync_only {
116        ($($item:tt)*) => {};
117    }
118
119    #[allow(unused_macros)]
120    macro_rules! async_only {
121        ($($item:tt)*) => { $($item)* };
122    }
123
124    #[path = "."]
125    mod __inner {
126        pub mod writer;
127    }
128    pub use __inner::*;
129}
130
131// ---------------------------------------------------------------------------
132// Default re-exports for backwards compatibility (sync)
133// ---------------------------------------------------------------------------
134
135#[cfg(feature = "sync")]
136pub use sync::*;
137
138// Re-exports from shared types
139pub use error::{CdError, CdResult};
140pub use layout::{LayoutInfo, LayoutManager};
141pub use options::{CdOptions, IsoOptions, UdfOptions};
142pub use tree::{Directory, FileData, FileEntry, FileExtent, FileTree};