Skip to content

Commit

Permalink
fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jl committed Dec 30, 2024
1 parent a1e9571 commit 0e9a890
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions connection_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (sc *snowflakeConn) processFileTransfer(
sfa.options.MultiPartThreshold = dataSizeThreshold
}
if sfa.options.arrayBindFromStream {
fs = getFileStreamAll(ctx)
fs, err = getFileStreamAll(ctx)
} else {
fs, err = getFileStream(ctx)
}
Expand Down Expand Up @@ -150,11 +150,11 @@ func getReaderFromContext(ctx context.Context) io.Reader {
return r
}

func getFileStreamAll(ctx context.Context) *bytes.Buffer {
func getFileStreamAll(ctx context.Context) (*bytes.Buffer, error) {
r := getReaderFromContext(ctx)
buf := new(bytes.Buffer)
buf.ReadFrom(r)
return buf
_, err := buf.ReadFrom(r)
return buf, err
}

func getFileStream(ctx context.Context) (*bytes.Buffer, error) {
Expand Down
14 changes: 10 additions & 4 deletions file_transfer_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ func (sfa *snowflakeFileTransferAgent) processFileCompressionType() error {
if err != nil {
return err
}
io.ReadAll(r) // flush out tee buffer
if _, err = io.ReadAll(r); err != nil { // flush out tee buffer
return err
}
} else {
mtype, err = mimetype.DetectFile(fileName)
}
Expand Down Expand Up @@ -880,7 +882,7 @@ func (sfa *snowflakeFileTransferAgent) uploadOneFile(meta *fileMetadata) (*fileM

if meta.srcStream != nil {
if meta.realSrcStream != nil {
// the whole file has been read in compressFileWithGzipFromStream
// the file has been fully read in compressFileWithGzipFromStream
meta.sha256Digest, meta.uploadSize, err = fileUtil.getDigestAndSizeForStream(&meta.realSrcStream)
} else {
r := getReaderFromContext(sfa.ctx)
Expand All @@ -889,7 +891,9 @@ func (sfa *snowflakeFileTransferAgent) uploadOneFile(meta *fileMetadata) (*fileM
}

var fullSrcStream bytes.Buffer
io.Copy(&fullSrcStream, meta.srcStream)
if _, err = io.Copy(&fullSrcStream, meta.srcStream); err != nil {
return nil, err
}

// continue reading the rest of the data in chunks
chunk := make([]byte, fileChunkSize)
Expand All @@ -902,7 +906,9 @@ func (sfa *snowflakeFileTransferAgent) uploadOneFile(meta *fileMetadata) (*fileM
}
fullSrcStream.Write(chunk[:n])
}
io.Copy(meta.srcStream, &fullSrcStream)
if _, err = io.Copy(meta.srcStream, &fullSrcStream); err != nil {
return nil, err
}
meta.sha256Digest, meta.uploadSize, err = fileUtil.getDigestAndSizeForStream(&meta.srcStream)
}
} else {
Expand Down
4 changes: 3 additions & 1 deletion file_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func (util *snowflakeFileUtil) compressFileWithGzipFromStream(ctx context.Contex

// compress the first chunk of data which was read before
var streamBuf bytes.Buffer
io.Copy(&streamBuf, *srcStream)
if _, err := io.Copy(&streamBuf, *srcStream); err != nil {
return nil, -1, err
}
if _, err := w.Write(streamBuf.Bytes()); err != nil {
return nil, -1, err
}
Expand Down

0 comments on commit 0e9a890

Please sign in to comment.