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
/// Default maximum input size: 256 MiB.
///
/// Chosen so that a single document load can never exceed ~2 GB of RSS on
/// realistic input (the worst-case amplification ratio measured across the
/// corpus is ~20×, so 256 MiB × 20 ≈ 5 GB — still above the default, but
/// the limit is a first-line guard, not a tight memory cap). Callers that
/// need larger files can pass a higher limit via `LoadOptions::max_file_bytes`.
pub const DEFAULT_MAX_FILE_BYTES: usize = 256 * 1024 * 1024;
/// Options that control how a PDF document is loaded into memory.
///
/// All options have safe defaults:
/// - `max_file_bytes`: `Some(256 MiB)` — rejects enormous inputs before
/// allocating the full object graph.
/// - `lazy_objstm`: `false` — ObjStm streams are decompressed eagerly, but
/// their container streams are dropped immediately after extraction
/// (saves the decompressed container bytes; Phase 2a optimisation).
///
/// # Example
///
/// ```rust,ignore
/// let opts = LoadOptions::new()
/// .max_file_bytes(64 * 1024 * 1024) // 64 MiB hard limit
/// .lazy_objstm(true); // defer ObjStm extraction
/// let doc = Document::load_mem_with_options(data, &opts)?;
/// doc.resolve_pending_object_streams()?; // required when lazy_objstm = true
/// ```