memory_efficient_streaming/
memory_efficient_streaming.rs1use std::env;
9use std::path::Path;
10use std::fs;
11use pptx_to_md::{ParserConfig, PptxContainer, Result};
12
13fn main() -> Result<()> {
14 let args: Vec<String> = env::args().collect();
16 let pptx_path = if args.len() > 1 {
17 &args[1]
18 } else {
19 eprintln!("Usage: cargo run --example memory_efficient_streaming <path/to/presentation.pptx>");
20 return Ok(());
21 };
22
23 println!("Processing PPTX file: {}", pptx_path);
24
25 let config = ParserConfig::builder()
27 .extract_images(true)
28 .build();
29
30 let mut streamer = PptxContainer::open(Path::new(pptx_path), config)?;
32
33 let output_dir = "output_streaming";
35 fs::create_dir_all(output_dir)?;
36
37 for slide_result in streamer.iter_slides() {
39 match slide_result {
40 Ok(slide) => {
41 println!("Processing slide {} ({} elements)", slide.slide_number, slide.elements.len());
42
43 if let Some(md_content) = slide.convert_to_md() {
44 let output_path = format!("{}/slide_{}.md", output_dir, slide.slide_number);
45 fs::write(&output_path, md_content)?;
46 println!("Saved slide {} to {}", slide.slide_number, output_path);
47 }
48 },
49 Err(e) => {
50 eprintln!("Error processing slide: {:?}", e);
51 }
52 }
53 }
54
55 println!("All slides processed successfully!");
56
57 Ok(())
58}