Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions clamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const (
)

type Clamd struct {
address string
address string
chunkSize int
}

type Stats struct {
Expand Down Expand Up @@ -258,7 +259,7 @@ the actual chunk. Streaming is terminated by sending a zero-length chunk. Note:
do not exceed StreamMaxLength as defined in clamd.conf, otherwise clamd will
reply with INSTREAM size limit exceeded and close the connection
*/
func (c *Clamd) ScanStream(r io.Reader, abort chan bool) (chan *ScanResult, error) {
func (c *Clamd) ScanStream(r io.Reader, abort <-chan struct{}) (chan *ScanResult, error) {
conn, err := c.newConnection()
if err != nil {
return nil, err
Expand All @@ -277,7 +278,7 @@ func (c *Clamd) ScanStream(r io.Reader, abort chan bool) (chan *ScanResult, erro
conn.sendCommand("INSTREAM")

for {
buf := make([]byte, CHUNK_SIZE)
buf := make([]byte, c.chunkSize)

nr, err := r.Read(buf)
if nr > 0 {
Expand Down Expand Up @@ -306,6 +307,6 @@ func (c *Clamd) ScanStream(r io.Reader, abort chan bool) (chan *ScanResult, erro
}

func NewClamd(address string) *Clamd {
clamd := &Clamd{address: address}
clamd := &Clamd{address: address, chunkSize: CHUNK_SIZE}
return clamd
}
30 changes: 30 additions & 0 deletions clamdBuilder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package clamd

type Builder struct {
address string
chunkSize int
}

func NewBuilder() *Builder {
return &Builder{
address: "",
chunkSize: CHUNK_SIZE,
}
}

func (b *Builder) WithAddress(address string) *Builder {
b.address = address
return b
}

func (b *Builder) WithChunkSize(chunkSize int) *Builder {
b.chunkSize = chunkSize
return b
}

func (b *Builder) Build() *Clamd {
return &Clamd{
address: b.address,
chunkSize: b.chunkSize,
}
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/dutchcoders/go-clamd

go 1.22.4