fuchsia_pkg/
package_archive.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use fuchsia_hash::Hash;
6use std::collections::BTreeMap;
7use std::io::{Read, Write};
8
9pub struct PackageArchiveBuilder {
10    entries: BTreeMap<String, (u64, Box<dyn Read>)>,
11}
12
13impl PackageArchiveBuilder {
14    pub fn with_meta_far(meta_far_size: u64, meta_far_content: Box<dyn Read>) -> Self {
15        Self { entries: BTreeMap::from([("meta.far".into(), (meta_far_size, meta_far_content))]) }
16    }
17
18    pub fn add_blob(&mut self, hash: Hash, blob_size: u64, blob_content: Box<dyn Read>) {
19        self.entries.insert(hash.to_string(), (blob_size, blob_content));
20    }
21
22    pub fn build(self, out: impl Write) -> Result<(), fuchsia_archive::Error> {
23        fuchsia_archive::write(out, self.entries)
24    }
25}