@@ -1,8 +1,7 @@
11# purescript-arraybuffer-builder
22
3−[](https://github.com/rowtype-yoga/purescript-arraybuffer-builder/actions)
3+[](https://github.com/jamesdbrock/purescript-arraybuffer-builder/actions)
44[](http://pursuit.purescript.org/packages/purescript-arraybuffer-builder/)
5−[](https://github.com/jamesdbrock)
65
76
87[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
@@ -51,26 +50,23 @@ Encode a `String` as UTF8 with a length prefix into our `Builder`.
5150
5251We give this as an example, rather than supporting it in the library, because
5352it depends on
54−[`Web.Encoding.TextEncoder`](https://pursuit.purescript.org/packages/purescript-web-encoding/docs/Web.Encoding.TextEncoder).
53+[`Data.TextEncoding.encodeUtf8`](https://pursuit.purescript.org/packages/purescript-text-encoding/docs/Data.TextEncoding#v:encodeUtf8).
5554
5655```purescript
57−import Effect.Class (class MonadEffect, liftEffect)
58−import Data.UInt (fromInt)
59−import Data.ArrayBuffer.Types (ArrayBuffer(..))
60−import Data.ArrayBuffer.Builder (PutM, putArrayBuffer, execPut, putUint32be)
56+import Data.ArrayBuffer.Builder (PutM, putArrayBuffer, execPut)
6157import Data.ArrayBuffer.Typed (buffer)
58+import Data.TextEncoding (encodeUtf8)
6259import Data.ArrayBuffer.ArrayBuffer (byteLength)
63−import Web.Encoding.TextEncoder (new, TextEncoder, encode)
6460
6561putStringUtf8 :: forall m. MonadEffect m => String -> PutM m Unit
6662putStringUtf8 s = do
67− textEncoder <- liftEffect new
68− let stringbuf = buffer $ encode s textEncoder
69− -- Put a 32-bit big-endian length for the utf8 string, in bytes.
70− putUint32be $ fromInt $ byteLength stringbuf
63+ let stringbuf = buffer $ encodeUtf8 s
64+ -- Put a 32-bit big-endian length prefix for the length of the utf8 string, in bytes.
65+ putInt32be $ byteLength stringbuf
7166 putArrayBuffer stringbuf
7267
73−arraybuffer :: ArrayBuffer <- execPut $ putStringUtf8 "🦝"
68+do
69+ arraybuffer :: ArrayBuffer <- execPut $ putStringUtf8 "BLM"
7470```
7571
7672### Serialize an `Array Int`
@@ -89,7 +85,7 @@ import Data.Array (length)
8985
9086putArrayInt32 :: forall m. MonadEffect m => Array Int -> PutM m Unit
9187putArrayInt32 xs = do
92− -- Put a 64-bit big-endian length prefix for the array.
88+ -- Put a 64-bit big-endian length prefix for the length of the array.
9389 putInt32be 0
9490 putInt32be $ length xs
9591 traverse_ putInt32be xs
@@ -109,7 +105,7 @@ import Data.Array (foldRecM)
109105
110106putArrayInt32 :: forall m. MonadEffect m => MonadRec m => Array Int -> PutM m Unit
111107putArrayInt32 xs = do
112− -- Put a 64-bit big-endian length prefix for the array.
108+ -- Put a 64-bit big-endian length prefix for the length of the array.
113109 putInt32be 0
114110 putInt32be $ length xs
115111 foldRecM (\_ x -> putInt32be x) unit xs
@@ -124,7 +120,7 @@ of the `PutM` builder expression are stack-safe.
124120
125121This package is only for writing `ArrayBuffer`s, not reading them.
126122See
127−[__parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview/)
123+[__purescript-parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview/)
128124for a way to deserialize from `ArrayBuffer` back to Purescript data.
129125
130126## Alternative packages for serializing to an `ArrayBuffer`