Skip to content

Commit b198ec8

Browse files
committed
Add tube.stream()
1 parent c8a8738 commit b198ec8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pwnlib/tubes/tube.py

+23
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,29 @@ def recv_thread():
826826
while t.is_alive():
827827
t.join(timeout = 0.1)
828828

829+
def stream(self, line_mode=True):
830+
"""stream()
831+
832+
Receive data until the tube exits, and print it to stdout.
833+
834+
Similar to :func:`interactive`, except that no input is sent.
835+
836+
Similar to ``print tube.recvall()`` except that data is printed
837+
as it is received, rather than after all data is received.
838+
839+
Arguments:
840+
line_mode(bool): Whether to receive line-by-line or raw data.
841+
"""
842+
data = True
843+
while data:
844+
if line_mode:
845+
data = self.recvline()
846+
else:
847+
data = self.recv()
848+
849+
if data:
850+
sys.stdout.write(data)
851+
829852
def clean(self, timeout = 0.05):
830853
"""clean(timeout = 0.05)
831854

0 commit comments

Comments
 (0)