about summary refs log tree commit diff stats
path: root/src/loader/request.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-10-25 12:35:11 +0200
committerbptato <nincsnevem662@gmail.com>2023-10-25 12:48:30 +0200
commit3f0a183d48a44cbbe642842fb60b69cca9e83390 (patch)
tree0aad7dfeaa3a9265e030b2ed2739de4e042a69a2 /src/loader/request.nim
parentb6e5390ec286747ce6789f9cfec54dec8dc18fa3 (diff)
downloadchawan-3f0a183d48a44cbbe642842fb60b69cca9e83390.tar.gz
reduce new() usage
Diffstat (limited to 'src/loader/request.nim')
-rw-r--r--src/loader/request.nim20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/loader/request.nim b/src/loader/request.nim
index 7596a0a2..78d38723 100644
--- a/src/loader/request.nim
+++ b/src/loader/request.nim
@@ -145,17 +145,17 @@ proc rsClose(s: Stream) = {.cast(tags: [WriteIOEffect]).}: #TODO TODO TODO ew.
     s.isource.setPosition(s.isource.getPosition() + len)
 
 proc newReadableStream*(isource: Stream): ReadableStream =
-  new(result)
-  result.isource = isource
-  result.readDataImpl = rsReadData
-  result.atEndImpl = rsAtEnd
-  result.closeImpl = rsClose
   var len: int
-  result.isource.read(len)
-  if len == 0:
-    result.isend = true
-  else:
-    result.isource.readStr(len, result.buf)
+  isource.read(len)
+  result = ReadableStream(
+    isource: isource,
+    readDataImpl: rsReadData,
+    atEndImpl: rsAtEnd,
+    closeImpl: rsClose,
+    isend: len == 0
+  )
+  if len != 0:
+    isource.readStr(len, result.buf)
 
 func newRequest*(url: URL, httpmethod = HTTP_GET, headers = newHeaders(),
     body = opt(string), multipart = opt(FormData), mode = RequestMode.NO_CORS,