diff --git a/CHANGELOG.md b/CHANGELOG.md index 9899541..94d35e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## Unreleased + +### Bug fixes +- Fixed `digest` command to work with remote URLs (HTTP, HTTPS, FTP, S3) + ## v0.21.0 -- 2026-03-27 ### Breaking changes diff --git a/src/digest.rs b/src/digest.rs index d36621a..8bbb43a 100644 --- a/src/digest.rs +++ b/src/digest.rs @@ -8,14 +8,24 @@ use ring::digest::{Context, SHA256}; /// Calculate the SHA256 digest of a file. /// /// This function takes a path to a file as input and returns the SHA256 digest of the file -/// as a hexadecimal string. +/// as a hexadecimal string. Supports both local files and remote URLs (HTTP, HTTPS, FTP, S3). +/// +/// Note: This function computes the hash of the raw file bytes without any decompression, +/// even if the file has a compression extension (e.g., `.gz`, `.bz2`). +/// +/// # Arguments +/// +/// * `path` - The path to the file. Can be a local file path or a remote URL. +/// +/// # Returns +/// +/// Returns the SHA256 digest as a hexadecimal string, or an error if the file cannot be read. pub fn get_sha256_digest(path: &str) -> Result { let mut context = Context::new(&SHA256); let mut buffer = [0; 1024]; - // Open file for reading - let file = std::fs::File::open(path)?; - let mut reader: Box = Box::new(std::io::BufReader::new(file)); + // Open file for reading (supports both local and remote files, no decompression) + let mut reader = crate::OneIo::new()?.get_reader_raw(path)?; loop { let count = reader.read(&mut buffer)?;