subxt_utils_fetchmetadata/
lib.rs

1// Copyright 2019-2024 Parity Technologies (UK) Ltd.
2// This file is dual-licensed as Apache-2.0 or GPL-3.0.
3// see LICENSE for license details.
4
5//! Subxt utils fetch metadata.
6
7#![cfg_attr(docsrs, feature(doc_cfg))]
8
9// Internal helper macros
10#[macro_use]
11mod macros;
12mod error;
13
14cfg_fetch_from_url! {
15    mod url;
16    pub use url::{from_url, from_url_blocking, MetadataVersion, Url};
17}
18
19pub use error::Error;
20
21/// Fetch metadata from a file in a blocking manner.
22pub fn from_file_blocking(path: &std::path::Path) -> Result<Vec<u8>, error::Error> {
23    use std::io::Read;
24
25    let to_err = |err| error::Error::Io(path.to_string_lossy().into(), err);
26    let mut file = std::fs::File::open(path).map_err(to_err)?;
27    let mut bytes = Vec::new();
28    file.read_to_end(&mut bytes).map_err(to_err)?;
29    Ok(bytes)
30}