Created
April 6, 2024 08:40
-
-
Save jelgun/03850cc812e485a6aecf514a475ae87c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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