Use Buffer.concat instead of string concatenation (#141)
* Bump dependency versions * Use Buffer.concat, then convert to string on end
This commit is contained in:
parent
5af653076f
commit
2a02d41954
@ -31,13 +31,13 @@
|
||||
"purescript-maybe": "^4.0.1",
|
||||
"purescript-newtype": "^3.0.0",
|
||||
"purescript-node-buffer": "^5.0.0",
|
||||
"purescript-node-child-process": "^5.0.0",
|
||||
"purescript-node-child-process": "^6.0.0",
|
||||
"purescript-node-fs": "^5.0.0",
|
||||
"purescript-node-fs-aff": "^6.0.0",
|
||||
"purescript-node-http": "^5.0.0",
|
||||
"purescript-node-streams": "^4.0.0",
|
||||
"purescript-nullable": "^4.1.1",
|
||||
"purescript-options": "^4.0.0",
|
||||
"purescript-options": "^5.0.0",
|
||||
"purescript-ordered-collections": "^1.6.1",
|
||||
"purescript-prelude": "^4.0.1",
|
||||
"purescript-psci-support": "^4.0.0",
|
||||
|
@ -82,8 +82,10 @@ instance bodyChunked ::
|
||||
read :: HTTP.Request -> Aff.Aff String
|
||||
read request = Aff.makeAff \done -> do
|
||||
let stream = HTTP.requestAsStream request
|
||||
buf <- Ref.new ""
|
||||
Stream.onDataString stream Encoding.UTF8 \str ->
|
||||
void $ Ref.modify (_ <> str) buf
|
||||
Stream.onEnd stream $ Ref.read buf >>= Either.Right >>> done
|
||||
bufs <- Ref.new []
|
||||
Stream.onData stream \buf ->
|
||||
void $ Ref.modify (_ <> [buf]) bufs
|
||||
Stream.onEnd stream do
|
||||
body <- Ref.read bufs >>= Buffer.concat >>= Buffer.toString Encoding.UTF8
|
||||
done $ Either.Right body
|
||||
pure Aff.nonCanceler
|
||||
|
Loading…
Reference in New Issue
Block a user