Skip to main content

bv_core/
data.rs

1use serde::{Deserialize, Serialize};
2
3use crate::error::{BvError, Result};
4
5#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
6#[serde(rename_all = "lowercase")]
7pub enum PostDownloadAction {
8    #[default]
9    Noop,
10    Extract,
11    Decompress,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct DataEntry {
16    pub id: String,
17    pub version: String,
18    pub description: Option<String>,
19    pub source_urls: Vec<String>,
20    /// Expected SHA-256 of the primary downloaded file as `sha256:<hex>`.
21    /// Optional: omit when the upstream file is mutable (e.g. NCBI
22    /// "current_release" pointers) or when no one has computed a real hash
23    /// yet. When set, `bv data fetch` enforces it strictly.
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub sha256: Option<String>,
26    /// Approximate compressed size in bytes. Optional. Used as a hint for
27    /// the progress bar when the server doesn't report Content-Length;
28    /// otherwise the server's value wins.
29    #[serde(default, skip_serializing_if = "Option::is_none")]
30    pub size_bytes: Option<u64>,
31    /// File format hint, e.g. `"tar"`, `"fasta_gz"`, `"raw"`.
32    pub format: String,
33    #[serde(default)]
34    pub post_download_action: PostDownloadAction,
35    pub license: Option<String>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct DataManifest {
40    pub data: DataEntry,
41}
42
43impl DataManifest {
44    pub fn from_toml_str(s: &str) -> Result<Self> {
45        toml::from_str(s).map_err(|e| BvError::ManifestParse(e.to_string()))
46    }
47}