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:
Ping Chen 2019-06-04 02:43:10 +09:00 committed by Connor Prussin
parent 5af653076f
commit 2a02d41954
2 changed files with 8 additions and 6 deletions

View File

@ -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",

View File

@ -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