diff options
author | bptato <nincsnevem662@gmail.com> | 2024-05-30 00:19:48 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-06-20 17:50:22 +0200 |
commit | 60dc37269cd2dc8cdf23d9f77680f6af9490032f (patch) | |
tree | 9a72ba24daffa546f92704e7e06cf84fded2d89d /src/io/bufwriter.nim | |
parent | a146a22b11cea39bc691417d9d9a1292b7177552 (diff) | |
download | chawan-60dc37269cd2dc8cdf23d9f77680f6af9490032f.tar.gz |
img, loader: separate out png codec into cgi, misc improvements
* multi-processed and sandboxed PNG decoding & encoding (through local CGI) * improved request body passing (including support for output id as response body) * simplified & faster blob()/text() - now every request starts suspended, and OngoingData.buf has been replaced with loader's buffering capability * image caching: we no longer pull bitmaps from the container after every single getLines call Next steps: replace our bespoke PNG decoder with something more usable, add other decoders, and make them stream.
Diffstat (limited to 'src/io/bufwriter.nim')
-rw-r--r-- | src/io/bufwriter.nim | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/io/bufwriter.nim b/src/io/bufwriter.nim index fd3c12a8..56e30f5b 100644 --- a/src/io/bufwriter.nim +++ b/src/io/bufwriter.nim @@ -5,8 +5,10 @@ import std/options import std/sets import std/tables +import img/bitmap import io/dynstream import io/socketstream +import loader/request import types/blob import types/color import types/formdata @@ -34,7 +36,7 @@ proc swrite*(writer: var BufferedWriter; b: bool) proc swrite*(writer: var BufferedWriter; url: URL) proc swrite*(writer: var BufferedWriter; tup: tuple) proc swrite*[I, T](writer: var BufferedWriter; a: array[I, T]) -proc swrite*(writer: var BufferedWriter; s: seq) +proc swrite*[T](writer: var BufferedWriter; s: openArray[T]) proc swrite*[U, V](writer: var BufferedWriter; t: Table[U, V]) proc swrite*(writer: var BufferedWriter; obj: object) proc swrite*(writer: var BufferedWriter; obj: ref object) @@ -43,6 +45,8 @@ proc swrite*(writer: var BufferedWriter; blob: Blob) proc swrite*[T](writer: var BufferedWriter; o: Option[T]) proc swrite*[T, E](writer: var BufferedWriter; o: Result[T, E]) proc swrite*(writer: var BufferedWriter; c: ARGBColor) {.inline.} +proc swrite*(writer: var BufferedWriter; o: RequestBody) +proc swrite*(writer: var BufferedWriter; bmp: Bitmap) const InitLen = sizeof(int) * 2 const SizeInit = max(64, InitLen) @@ -130,7 +134,7 @@ proc swrite*[I, T](writer: var BufferedWriter; a: array[I, T]) = for x in a: writer.swrite(x) -proc swrite*(writer: var BufferedWriter; s: seq) = +proc swrite*[T](writer: var BufferedWriter; s: openArray[T]) = writer.swrite(s.len) for x in s: writer.swrite(x) @@ -188,3 +192,21 @@ proc swrite*[T, E](writer: var BufferedWriter; o: Result[T, E]) = proc swrite*(writer: var BufferedWriter; c: ARGBColor) = writer.swrite(uint32(c)) + +proc swrite*(writer: var BufferedWriter; o: RequestBody) = + writer.swrite(o.t) + case o.t + of rbtNone: discard + of rbtString: writer.swrite(o.s) + of rbtMultipart: writer.swrite(o.multipart) + of rbtOutput: writer.swrite(o.outputId) + +proc swrite*(writer: var BufferedWriter; bmp: Bitmap) = + writer.swrite(bmp of ImageBitmap) + writer.swrite(bmp.width) + writer.swrite(bmp.height) + if bmp of ImageBitmap: + writer.swrite(bmp.px) + else: + writer.swrite(NetworkBitmap(bmp).outputId) + writer.swrite(NetworkBitmap(bmp).imageId) |