Skip to content

Commit

Permalink
move chunk out of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jbahk committed Feb 9, 2022
1 parent 47a5940 commit a106068
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions encrypt_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ 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
} else if n%aes.BlockSize != 0 || n != chunkSize {
chunk = padBytesLength(chunk[:n], aes.BlockSize)
}
mode.CryptBlocks(cipherText, chunk)
out.Write(cipherText[:len(chunk)])
out.Write(cipherText[:n])

}
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const (
reasonKey = "reason"
errorNumberKey = "ErrorNumber"
stacktraceKey = "Stacktrace"
exceptionKey = "Exception"
)

const (
Expand Down

0 comments on commit a106068

Please sign in to comment.