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
use crate::{Archive, Limits, PgDumpError};
use std::{fs::File, io::BufReader, path::Path};
impl Archive<BufReader<File>> {
/// Opens a PostgreSQL custom-format archive from a filesystem path.
///
/// This is a convenience wrapper around the same generic [`Archive::open`] parser
/// used for arbitrary `Read + Seek` sources. The file is wrapped in a standard
/// [`BufReader`], archive metadata is parsed eagerly, and selected entry payloads
/// remain lazy until an entry/row API is used.
///
/// File-opening failures are returned as [`PgDumpError::Io`] with the underlying
/// [`std::io::Error`] preserved as the error source.
///
/// # Example
///
/// ```no_run
/// use pgdumpx::Archive;
///
/// # fn main() -> Result<(), pgdumpx::PgDumpError> {
/// let archive = Archive::open_path("backup.dump")?;
/// assert!(!archive.entries().is_empty());
/// # Ok(())
/// # }
/// ```
pub fn open_path(path: impl AsRef<Path>) -> Result<Self, PgDumpError> {
Self::open_path_with_limits(path, Limits::default())
}
/// Opens a filesystem archive with explicit structural [`Limits`].
///
/// This only adds `File::open` and [`BufReader`] around
/// [`Archive::open_with_limits`]; it does not introduce a filesystem-specific parser,
/// decompression path, or payload-read policy. Raw-output and row-scan budgets remain
/// controlled separately by [`crate::EntryReadLimits`] and [`crate::ScanLimits`].
///
/// # Example
///
/// ```no_run
/// use pgdumpx::{Archive, Limits};
///
/// # fn main() -> Result<(), pgdumpx::PgDumpError> {
/// let limits = Limits::default_compatible().with_max_toc_entries(50_000);
/// let archive = Archive::open_path_with_limits("backup.dump", limits)?;
/// assert!(!archive.entries().is_empty());
/// # Ok(())
/// # }
/// ```
pub fn open_path_with_limits(
path: impl AsRef<Path>,
limits: Limits,
) -> Result<Self, PgDumpError> {
let file = File::open(path).map_err(|source| PgDumpError::Io { offset: 0, source })?;
Self::open_with_limits(BufReader::new(file), limits)
}
}