diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-22 20:14:08 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-22 20:14:19 +0100 |
commit | 78ffc938fa7e4baad0a55625026b765d215be1aa (patch) | |
tree | 857db2e963efb13933d1e7954e9d4dc657b6f11d /src/loader | |
parent | def15ede4fbd686b0ee9b193f41b2a47190aa43a (diff) | |
download | chawan-78ffc938fa7e4baad0a55625026b765d215be1aa.tar.gz |
Replace Chakasu with Chagashi
The API is horrid :( but at least it copies less. TODO: think of a better API.
Diffstat (limited to 'src/loader')
-rw-r--r-- | src/loader/loader.nim | 2 | ||||
-rw-r--r-- | src/loader/response.nim | 18 |
2 files changed, 9 insertions, 11 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index d859ae34..3c974c95 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -51,7 +51,7 @@ import types/url import utils/mimeguess import utils/twtstr -import chakasu/charset +import chagashi/charset export request export response diff --git a/src/loader/response.nim b/src/loader/response.nim index 0869a73e..6168aff6 100644 --- a/src/loader/response.nim +++ b/src/loader/response.nim @@ -1,5 +1,4 @@ import std/streams -import std/unicode import bindings/quickjs import io/promise @@ -11,9 +10,9 @@ import loader/request import types/blob import types/url -import chakasu/charset -import chakasu/decoderstream -import chakasu/encoderstream +import chagashi/charset +import chagashi/decoder +import chagashi/validator type ResponseType* = enum @@ -106,13 +105,12 @@ proc text*(response: Response): Promise[JSResult[string]] {.jsfunc.} = CHARSET_UTF_8 else: response.charset - if cs == CHARSET_UTF_8 and s.validateUtf8() == -1: - ok(s) + #TODO this is inefficient + # maybe add a JS type that turns a seq[char] into JS strings + if cs in {CHARSET_UTF_8, CHARSET_UNKNOWN}: + ok(s.toValidUTF8()) else: - let ss = newStringStream(s) - let ds = newDecoderStream(ss, cs) - let es = newEncoderStream(ds, CHARSET_UTF_8) - return ok(es.readAll()) + ok(newTextDecoder(cs).decodeAll(s)) ) proc blob*(response: Response): Promise[JSResult[Blob]] {.jsfunc.} = |