oxgraph_postgres/artifact/
mod.rs1mod metadata;
4mod sections;
5
6pub use metadata::{
7 PostgresMetadata, PostgresSectionError, SNAPSHOT_KIND_PG_CATALOG, SNAPSHOT_KIND_PG_METADATA,
8};
9use oxgraph_snapshot::Snapshot;
10pub use sections::{attach_metadata, attach_postgres_sections};
11
12use crate::error::{BuildError, PostgresGraphError};
13
14pub fn load_snapshot_bytes(bytes: &[u8]) -> Result<Snapshot<'_>, PostgresGraphError> {
24 Snapshot::open(bytes).map_err(PostgresGraphError::from)
25}
26
27pub fn validate_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
37 let _ = Snapshot::open(bytes)?;
38 Ok(bytes.to_vec())
39}
40
41pub fn read_metadata(snapshot: &Snapshot<'_>) -> Result<PostgresMetadata, PostgresGraphError> {
52 metadata::read_postgres_metadata(snapshot).map_err(|error| match error {
53 PostgresSectionError::Snapshot(snapshot_error) => {
54 PostgresGraphError::Snapshot(snapshot_error)
55 }
56 PostgresSectionError::MissingSection => {
57 PostgresGraphError::Build(BuildError::MissingMetadataSection)
58 }
59 PostgresSectionError::Malformed(message) => {
60 PostgresGraphError::Build(BuildError::MalformedMetadata(message))
61 }
62 })
63}
64
65pub fn write_snapshot_bytes(bytes: &[u8]) -> Result<Vec<u8>, PostgresGraphError> {
75 validate_snapshot_bytes(bytes)
76}