Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 2efcfca

Browse files
authored
Merge pull request #1 from gangverk/allow_max_buffer_size
allow chunk size to be specified
2 parents 5c5e33b + 6282de2 commit 2efcfca

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/clamd/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ def _file_system_scan(self, command, file):
166166
finally:
167167
self._close_socket()
168168

169-
def instream(self, buff):
169+
def instream(self, buff, max_chunk_size=1024):
170170
"""
171171
Scan a buffer
172172
173173
buff filelikeobj: buffer to scan
174+
max_chunk_size int: Maximum size of chunk to send to clamd in bytes
175+
MUST be < StreamMaxLength in /etc/clamav/clamd.conf
174176
175177
return:
176178
- (dict): {filename1: ("virusname", "status")}
@@ -184,15 +186,13 @@ def instream(self, buff):
184186
self._init_socket()
185187
self._send_command('INSTREAM')
186188

187-
max_chunk_size = 1024 # MUST be < StreamMaxLength in /etc/clamav/clamd.conf
188-
189189
chunk = buff.read(max_chunk_size)
190190
while chunk:
191191
size = struct.pack(b'!L', len(chunk))
192-
self.clamd_socket.send(size + chunk)
192+
self.clamd_socket.sendall(size + chunk)
193193
chunk = buff.read(max_chunk_size)
194194

195-
self.clamd_socket.send(struct.pack(b'!L', 0))
195+
self.clamd_socket.sendall(struct.pack(b'!L', 0))
196196

197197
result = self._recv_response()
198198

@@ -231,7 +231,7 @@ def _send_command(self, cmd, *args):
231231
concat_args = ' ' + ' '.join(args)
232232

233233
cmd = 'n{cmd}{args}\n'.format(cmd=cmd, args=concat_args).encode('utf-8')
234-
self.clamd_socket.send(cmd)
234+
self.clamd_socket.sendall(cmd)
235235

236236
def _recv_response(self):
237237
"""

0 commit comments

Comments
 (0)