Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit 69ffe59

Browse files
add stream_safe method for File
1 parent ff41594 commit 69ffe59

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

stream/io/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ def stream(self) -> _Stream[_typing.AnyStr]:
2121
raise self.NotSupported
2222
return _IterStream(self)
2323

24+
@classmethod
25+
def stream_safe(cls, *args, **kwargs) -> _Stream[_typing.AnyStr]:
26+
def __iter() -> _typing.Iterator[_typing.AnyStr]:
27+
with cls(*args, **kwargs) as f:
28+
yield from f.stream
29+
30+
return _IterStream(__iter())
31+
2432
def input(self, lines: _typing.Iterable[_typing.AnyStr]) -> None:
2533
"""
2634
Write a sequence of lines.

0 commit comments

Comments
 (0)