From 7002411a045ee6b7b5adc7ea75dd86ff2d38b822 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 26 Nov 2025 11:50:19 +0200 Subject: [PATCH] tools: add `--sha3-256` support for checksumming the content that `v download` saves --- cmd/tools/vdownload.v | 15 ++++++++++----- vlib/v/help/other/download.txt | 5 +++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cmd/tools/vdownload.v b/cmd/tools/vdownload.v index ac2e208b1..2bef4df4f 100644 --- a/cmd/tools/vdownload.v +++ b/cmd/tools/vdownload.v @@ -5,12 +5,14 @@ import flag import net.http import crypto.sha1 import crypto.sha256 +import crypto.sha3 struct Context { mut: show_help bool show_sha1 bool show_sha256 bool + show_sha3_256 bool target_folder string output string continue_on_failure bool @@ -38,9 +40,10 @@ fn main() { ctx.output = fp.string('output', `o`, '', 'Write output to the given file, instead of inferring it from the final part of the URL. All intermediate folders will be created, if they do not exist.') ctx.show_sha1 = fp.bool('sha1', `1`, false, 'Show the SHA1 hash of the downloaded file.') ctx.show_sha256 = fp.bool('sha256', `2`, false, 'Show the SHA256 hash of the downloaded file.') + ctx.show_sha3_256 = fp.bool('sha3-256', `3`, false, 'Show the SHA3-256 (Keccak) hash of the downloaded file.') ctx.continue_on_failure = fp.bool('continue', `c`, false, 'Continue on download failures. If you download 5 URLs, and several of them fail, continue without error. False by default.') - ctx.retries = fp.int('retries', `r`, 10, 'Number of retries, when an URL fails to download.') - ctx.delay = time.Duration(u64(fp.float('delay', `d`, 1.0, 'Delay in seconds, after each retry.') * time.second)) + ctx.retries = fp.int('retries', `r`, 10, 'Number of retries, when an URL fails to download. The default is 10.') + ctx.delay = time.Duration(u64(fp.float('delay', `d`, 1.0, 'Delay in seconds, after each retry. The default is 1 second.') * time.second)) ctx.should_run = fp.bool('run', `R`, false, 'Run, after the script/program is completely downloaded.') ctx.delete_after_run = fp.bool('delete-after-run', `D`, false, 'Delete the downloaded script/program, after it has been run.') if ctx.show_help { @@ -108,10 +111,9 @@ fn main() { log.info(' Removing: ${fpath}') os.rm(fpath) or {} } - if !ctx.show_sha256 && !ctx.show_sha1 { + if !ctx.show_sha256 && !ctx.show_sha1 && !ctx.show_sha3_256 { continue } - fbytes := os.read_bytes(fname)! if ctx.show_sha1 { mut digest1 := sha1.new() @@ -120,7 +122,6 @@ fn main() { hash1 := sum1.hex() log.info(' SHA1: ${hash1}') } - if ctx.show_sha256 { mut digest256 := sha256.new() digest256.write(fbytes)! @@ -128,6 +129,10 @@ fn main() { hash256 := sum256.hex() log.info(' SHA256: ${hash256}') } + if ctx.show_sha3_256 { + hash3_256 := sha3.sum256(fbytes).hex() + log.info(' SHA3-256: ${hash3_256}') + } } println('Downloaded: ${downloaded} file(s) . Elapsed time: ${sw.elapsed()} . Errors: ${errors} .') if !ctx.continue_on_failure && errors > 0 { diff --git a/vlib/v/help/other/download.txt b/vlib/v/help/other/download.txt index a58a108d1..1120dc63b 100644 --- a/vlib/v/help/other/download.txt +++ b/vlib/v/help/other/download.txt @@ -13,8 +13,9 @@ Options: -o, --output Write output to the given file, instead of inferring it from the final part of the URL. All intermediate folders will be created, if they do not exist. -1, --sha1 Show the SHA1 hash of the downloaded file. -2, --sha256 Show the SHA256 hash of the downloaded file. + -3, --sha3-256 Show the SHA3-256 (Keccak) hash of the downloaded file. -c, --continue Continue on download failures. If you download 5 URLs, and several of them fail, continue without error. False by default. - -r, --retries Number of retries, when an URL fails to download. - -d, --delay Delay in seconds, after each retry. + -r, --retries Number of retries, when an URL fails to download. The default is 10. + -d, --delay Delay in seconds, after each retry. The default is 1 second. -R, --run Run, after the script/program is completely downloaded. -D, --delete-after-run Delete the downloaded script/program, after it has been run. -- 2.39.5