You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BufferedReader is probably the best abstraction in NIOFileSystem to stream a bunch of data. Real world examples include for example JSON lines (JSONL).
I'd expect to be able to write
tryawaitFileSystem.shared.withFileHandle(forReadingAt:"many-gigabytes.jsonl"){ file invarreader= file.bufferedReader(capacity:.mebibytes(4))
for line in tryawait reader.lines{letthing=tryJSONDecoder().decode(Thing.self, from: line)tryawaitprocess(thing)}}
And for more complex schemes that aren't just newlines, I'd like to be able to write something composable on BufferedReader.
not actually correct because I can only easily test for 1 byte (UInt8("\n")). If I wanted to support \r\n & \n, then this would get a lot more messy
SwiftNIO version/commit hash
2.77.0
FWIW, I also have another thing which allows me to use
tryawaitFileSystem.shared.withFileHandle(forReadingAt:"many-gigabytes.jsonl"){ file in
for tryawaitline in file.lines {letthing=tryJSONDecoder().decode(Thing.self, from: line)tryawaitprocess(thing)}}
I understand your ask here. IMO we should start with providing an AsyncSequence way for now since this is the standard API for asynchronous streaming at this point.
I personally feel like a general protocol AsyncReader and protocol AsyncWriter is something very useful that we might want to introduce at the NIO level. Though I personally feel like they are standard library concepts.
Expected behavior
BufferedReader
is probably the best abstraction inNIOFileSystem
to stream a bunch of data. Real world examples include for example JSON lines (JSONL).I'd expect to be able to write
And for more complex schemes that aren't just newlines, I'd like to be able to write something composable on BufferedReader.
Actual behavior
Right now I use
But this is
while true
+guard !seenEOF
(_, _) =
UInt8("\n")
). If I wanted to support\r\n
&\n
, then this would get a lot more messySwiftNIO version/commit hash
2.77.0
FWIW, I also have another thing which allows me to use
but, it's very complex:
The text was updated successfully, but these errors were encountered: