Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, OneIoError> {
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<dyn std::io::Read + Send> = 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)?;
Expand Down
Loading