Skip to content

Instantly share code, notes, and snippets.

@jelgun
Created April 6, 2024 08:40
Show Gist options
  • Select an option

  • Save jelgun/03850cc812e485a6aecf514a475ae87c to your computer and use it in GitHub Desktop.

Select an option

Save jelgun/03850cc812e485a6aecf514a475ae87c to your computer and use it in GitHub Desktop.
// ClamavReader is a custom reader used for clamavClient. The default reader used in the clamavClient does not read the last
// chunk of bytes when Read() returns EOF alongside read bytes, which is the case for reading responses from
// alicloud signed URLs. This custom reader makes sure that the EOF is returned only when no bytes were read.
type ClamavReader struct {
ReachedEOF bool
Reader io.Reader
}
func (c *ClamavReader) Read(p []byte) (int, error) {
if c.ReachedEOF {
return 0, io.EOF
}
n, err := c.Reader.Read(p)
if err == io.EOF && n > 0 {
c.ReachedEOF = true
return n, nil
}
return n, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment