From a106068d0cfd260439b7735c2235bc2dbda64287 Mon Sep 17 00:00:00 2001 From: sfc-gh-jbahk Date: Wed, 9 Feb 2022 17:47:45 +0000 Subject: [PATCH] move chunk out of loop --- encrypt_util.go | 4 ++-- file_util.go | 2 +- telemetry.go | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/encrypt_util.go b/encrypt_util.go index 8ba1a453c..ba1a945dc 100644 --- a/encrypt_util.go +++ b/encrypt_util.go @@ -71,10 +71,10 @@ func encryptStream( mode := cipher.NewCBCEncrypter(block, ivData) cipherText := make([]byte, chunkSize) + chunk := make([]byte, chunkSize) // encrypt file with CBC for { - chunk := make([]byte, chunkSize) n, err := src.Read(chunk) if n == 0 || err != nil { break @@ -82,7 +82,7 @@ func encryptStream( chunk = padBytesLength(chunk[:n], aes.BlockSize) } mode.CryptBlocks(cipherText, chunk) - out.Write(cipherText[:len(chunk)]) + out.Write(cipherText[:n]) } if err != nil { diff --git a/file_util.go b/file_util.go index 82639bb3a..acf636398 100644 --- a/file_util.go +++ b/file_util.go @@ -63,9 +63,9 @@ func (util *snowflakeFileUtil) compressFileWithGzip(fileName string, tmpDir stri func (util *snowflakeFileUtil) getDigestAndSizeForStream(stream **bytes.Buffer) (string, int64, error) { m := sha256.New() r := getReaderFromBuffer(stream) + chunk := make([]byte, fileChunkSize) for { - chunk := make([]byte, fileChunkSize) n, err := r.Read(chunk) if err == io.EOF { break diff --git a/telemetry.go b/telemetry.go index 8015cb128..369f9b743 100644 --- a/telemetry.go +++ b/telemetry.go @@ -27,7 +27,6 @@ const ( reasonKey = "reason" errorNumberKey = "ErrorNumber" stacktraceKey = "Stacktrace" - exceptionKey = "Exception" ) const (