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
7mod error;
8
9#[cfg(feature = "url")]
10mod url;
11#[cfg(feature = "url")]
12pub use url::{MetadataVersion, Url, from_url, from_url_blocking};
13
14pub use error::Error;
15
16/// Fetch metadata from a file in a blocking manner.
17pub fn from_file_blocking(path: &std::path::Path) -> Result<Vec<u8>, error::Error> {
18    use std::io::Read;
19
20    let to_err = |err| error::Error::Io(path.to_string_lossy().into(), err);
21    let mut file = std::fs::File::open(path).map_err(to_err)?;
22    let mut bytes = Vec::new();
23    file.read_to_end(&mut bytes).map_err(to_err)?;
24    Ok(bytes)
25}