From 7bc594c1e9bb7b655871042cc5b6be955746be37 Mon Sep 17 00:00:00 2001 From: Redmomn <109732988+Redmomn@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:56:09 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=B8=80=E7=82=B9=E5=B0=8F=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/crypto/hash.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/utils/crypto/hash.go b/utils/crypto/hash.go index 1a06f2a3..be8e9b3b 100644 --- a/utils/crypto/hash.go +++ b/utils/crypto/hash.go @@ -62,11 +62,10 @@ func ComputeMd5AndSha1AndLength(r io.ReadSeeker) ([]byte, []byte, uint64) { defer func(r io.ReadSeeker, offset int64, whence int) { _, _ = r.Seek(offset, whence) }(r, 0, io.SeekStart) + _, _ = r.Seek(0, io.SeekStart) md5r := md5.New() sha1r := sha1.New() - _, _ = r.Seek(0, io.SeekStart) - length, _ := io.Copy(md5r, r) - _, _ = r.Seek(0, io.SeekStart) - _, _ = io.Copy(sha1r, r) + mr := io.MultiWriter(md5r, sha1r) + length, _ := io.Copy(mr, r) return md5r.Sum(nil), sha1r.Sum(nil), uint64(length) }