From c8e6d65b7979dc22dee3c51effd321f92ab17cd1 Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 20 Mar 2024 21:27:47 +0100 Subject: buffer: also buffer reads for packets Since we know the length of packets, we can also read them in in one call. Though I really wish we could do this without the StringStream. --- src/io/bufwriter.nim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/io') diff --git a/src/io/bufwriter.nim b/src/io/bufwriter.nim index 99c7ed94..57219100 100644 --- a/src/io/bufwriter.nim +++ b/src/io/bufwriter.nim @@ -48,10 +48,11 @@ proc deinit*(writer: var BufferedWriter) = writer.bufLen = 0 template withWriter*(stream: DynStream; w, body: untyped) = - var w {.inject.} = stream.initWriter() - body - w.flush() - w.deinit() + block: + var w {.inject.} = stream.initWriter() + body + w.flush() + w.deinit() proc swrite*(writer: var BufferedWriter; n: SomeNumber) proc swrite*[T](writer: var BufferedWriter; s: set[T]) -- cgit