Skip to content

Commit 2af36f8

Browse files
committed
Use BytesIO as read buffer
1 parent 0a9ac79 commit 2af36f8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 0.4.0 (2018-XX-XX)
44

5+
- Use `BytesIO` as read buffer
6+
57
## 0.3.0 (2018-09-25)
68

79
- Improved receive messages logic

pynats/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,19 @@ def _recv(self, *commands: Pattern[bytes]) -> Tuple[Pattern[bytes], Match[bytes]
266266
return command, result
267267

268268
def _readline(self, *, size: int = None) -> bytes:
269-
read = b""
269+
read = io.BytesIO()
270270

271271
while True:
272272
line = cast(bytes, self._socket_file.readline())
273-
read += line
273+
read.write(line)
274274

275275
if size is not None:
276-
if len(self._strip(read)) == size:
276+
if read.tell() == size + len(_CRLF_):
277277
break
278278
elif line.endswith(_CRLF_):
279279
break
280280

281-
return read
281+
return read.getvalue()
282282

283283
def _strip(self, line: bytes) -> bytes:
284284
return line[: -len(_CRLF_)]

0 commit comments

Comments
 (0)