#safe-network #download #repository #binaries #unpack #released #unpacking

sn-releases

下载并解压来自safe_network仓库发布的二进制文件

18个版本

新版本 0.2.7 2024年8月2日
0.2.6 2024年5月31日
0.2.0 2024年3月19日
0.1.9 2024年3月19日
0.1.2 2023年10月24日

#78压缩

Download history 2400/week @ 2024-04-17 1702/week @ 2024-04-24 2157/week @ 2024-05-01 2490/week @ 2024-05-08 3721/week @ 2024-05-15 3053/week @ 2024-05-22 4490/week @ 2024-05-29 2556/week @ 2024-06-05 2166/week @ 2024-06-12 1491/week @ 2024-06-19 1337/week @ 2024-06-26 1616/week @ 2024-07-03 1905/week @ 2024-07-10 2461/week @ 2024-07-17 1981/week @ 2024-07-24 2001/week @ 2024-07-31

8,543 每月下载量
3 crates 中使用

GPL-3.0 许可证

24KB
386 代码行

sn-releases

一个简单的crate,用于下载和解压来自safe_network仓库发布的二进制文件。

示例用法

let temp_dir = TempDir::new("safenode")?;
let pb = Arc::new(ProgressBar::new(0));
pb.set_style(ProgressStyle::default_bar()
    .template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta})")?
    .progress_chars("#>-"));
let pb_clone = pb.clone();
let callback: Box<dyn Fn(u64, u64) + Send + Sync> = Box::new(move |downloaded, total| {
    pb_clone.set_length(total);
    pb_clone.set_position(downloaded);
});

let release_repo = <dyn SafeReleaseRepositoryInterface>::default_config();
let archive_path = release_repo
    .download_release_from_s3(
        &ReleaseType::Safenode,
        "0.94.0",
        &Platform::LinuxMusl,
        &ArchiveType::TarGz,
        temp_dir.path(),
        &callback,
    )
    .await?;

pb.finish_with_message("Download complete");

release_repo.extract_release_archive(&archive_path, temp_dir.path())?;

测试

crate的用户可以针对SafeReleaseRepositoryInterface进行编程,然后对其进行模拟并在单元测试中使用。

pub fn function_under_test(release_repo: Box<dyn SafeReleaseRepositoryInterface>) -> Result<()> {
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::function_under_test;
    use async_trait::async_trait;
    use mockall::mock;
    use mockall::predicate::*;
    use sn_releases::{
        ArchiveType, Platform, ProgressCallback, ReleaseType, Result as SnReleaseResult,
        SafeReleaseRepositoryInterface,
    };
    use std::path::{Path, PathBuf};

    mock! {
        pub SafeReleaseRepository {}
        #[async_trait]
        impl SafeReleaseRepositoryInterface for SafeReleaseRepository {
            async fn get_latest_version(&self, release_type: &ReleaseType) -> SnReleaseResult<String>;
            async fn download_release_from_s3(
                &self,
                release_type: &ReleaseType,
                version: &str,
                platform: &Platform,
                archive_type: &ArchiveType,
                dest_path: &Path,
                callback: &ProgressCallback,
            ) -> SnReleaseResult<PathBuf>;
            fn extract_release_archive(&self, archive_path: &Path, dest_dir_path: &Path)
                -> SnReleaseResult<PathBuf>;
        }
    }

    #[test]
    fn test_release_repo() {
        let release_type = ReleaseType::Safe;
        let mut mock = MockSafeReleaseRepository::new();
        mock.expect_get_latest_version()
            .withf(move |arg| *arg == release_type)
            .times(1)
            .returning(|_| Ok("0.93.12".to_string()));
        let result = function_under_test(Box::new(mock));
        assert!(result.is_ok());
    }
}

许可证

此Safe Network仓库根据通用公共许可证(GPL),版本3(LICENSE http://www.gnu.org/licenses/gpl-3.0.en.html)。

有关更多详细信息,请参阅LICENSE文件。

依赖关系

~16–33MB
~480K SLoC