diff --git a/clamd.go b/clamd.go index 5199f63..0477d8d 100644 --- a/clamd.go +++ b/clamd.go @@ -41,7 +41,8 @@ const ( ) type Clamd struct { - address string + address string + chunkSize int } type Stats struct { @@ -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 @@ -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 { @@ -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 } diff --git a/clamdBuilder.go b/clamdBuilder.go new file mode 100644 index 0000000..a066b40 --- /dev/null +++ b/clamdBuilder.go @@ -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, + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2344300 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/dutchcoders/go-clamd + +go 1.22.4