From 20dd7d777a89d1bc3f654682efc5f92a8a486d79 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 2 Aug 2019 18:00:41 -0700 Subject: [PATCH] More efficiently remove trailing newline from message --- libp2p/network/connection/raw_connection.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libp2p/network/connection/raw_connection.py b/libp2p/network/connection/raw_connection.py index abde0066..3d12f0d5 100644 --- a/libp2p/network/connection/raw_connection.py +++ b/libp2p/network/connection/raw_connection.py @@ -34,11 +34,7 @@ class RawConnection(IRawConnection): async def read(self) -> bytes: line = await self.reader.readline() - adjusted_line = line.decode().rstrip("\n") - - # TODO: figure out a way to remove \n without going back and forth with - # encoding and decoding - return adjusted_line.encode() + return line.rstrip(b"\n") def close(self) -> None: self.writer.close()