From 9bd14b4cbf584c524ffe1bd1ecebe2bed90a5cb3 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 18 Jan 2022 22:52:14 +0100 Subject: [PATCH] Yeah this doesn't work [CI SKIP] --- src/main.v | 2 +- src/util.v | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.v b/src/main.v index 2fcf1dc..8a73822 100644 --- a/src/main.v +++ b/src/main.v @@ -104,7 +104,7 @@ fn reader_to_file(mut reader io.BufferedReader, length int, path string) ? { fn main() { // archive.list_filenames() - res := pkg.read_pkg('test/homebank-5.5.1-1-x86_64.pkg.tar.zst') or { + res := pkg.read_pkg('test/homebank-5.5.3-1-x86_64.pkg.tar.zst') or { eprintln(err.msg) return } diff --git a/src/util.v b/src/util.v index cb17c3f..19d174f 100644 --- a/src/util.v +++ b/src/util.v @@ -5,13 +5,14 @@ import crypto.md5 import crypto.sha256 // hash_file returns the md5 & sha256 hash of a given file +// TODO actually implement sha256 pub fn hash_file(path &string) ?(string, string) { file := os.open(path) or { return error('Failed to open file.') } mut md5sum := md5.new() mut sha256sum := sha256.new() - buf_size := i32(1_000_000) + buf_size := int(1_000_000) mut buf := []byte{len: buf_size} mut bytes_left := os.file_size(path) @@ -21,10 +22,12 @@ pub fn hash_file(path &string) ?(string, string) { bytes_left -= u64(bytes_read) if bytes_left > buf_size { - md5sum.write(buf) - sha256sum.write(buf) + // For now we'll assume that this always works + md5sum.write(buf) or {} + // sha256sum.write(buf) or {} } } - return md5sum.sum(buf).hex(), sha256sum.sum(buf).hex() + // return md5sum.sum(buf).hex(), sha256sum.sum(buf).hex() + return md5sum.sum(buf).hex(), '' }