diff --git a/CHANGELOG.md b/CHANGELOG.md index 0395721..b3d58e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v3.1.0 2022-12-10 + +- Transfer to __rowtype-yoga__. +- Docs. + ## v3.0.1 2022-05-04 CI repair. Change `test.dhall` to `spago-dev.dhall`. diff --git a/README.md b/README.md index d56daed..17fdd89 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # purescript-arraybuffer-builder -[![CI](https://github.com/jamesdbrock/purescript-arraybuffer-builder/workflows/CI/badge.svg?branch=master)](https://github.com/jamesdbrock/purescript-arraybuffer-builder/actions) +[![CI](https://github.com/rowtype-yoga/purescript-arraybuffer-builder/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-arraybuffer-builder/actions) [![Pursuit](http://pursuit.purescript.org/packages/purescript-arraybuffer-builder/badge)](http://pursuit.purescript.org/packages/purescript-arraybuffer-builder/) +[![Maintainer: jamesdbrock](https://img.shields.io/badge/maintainer-jamesdbrock-teal.svg)](https://github.com/jamesdbrock) [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) @@ -50,23 +51,23 @@ Encode a `String` as UTF8 with a length prefix into our `Builder`. We give this as an example, rather than supporting it in the library, because it depends on -[`Data.TextEncoding.encodeUtf8`](https://pursuit.purescript.org/packages/purescript-text-encoding/docs/Data.TextEncoding#v:encodeUtf8). +[`Web.Encoding.TextEncoder`](https://pursuit.purescript.org/packages/purescript-web-encoding/docs/Web.Encoding.TextEncoder). ```purescript import Data.ArrayBuffer.Builder (PutM, putArrayBuffer, execPut) import Data.ArrayBuffer.Typed (buffer) -import Data.TextEncoding (encodeUtf8) import Data.ArrayBuffer.ArrayBuffer (byteLength) +import Web.Encoding.TextEncoder (new, textEncoder) putStringUtf8 :: forall m. MonadEffect m => String -> PutM m Unit putStringUtf8 s = do - let stringbuf = buffer $ encodeUtf8 s - -- Put a 32-bit big-endian length prefix for the length of the utf8 string, in bytes. + textEncoder <- liftEffect new + let stringbuf = buffer $ encode s textEncoder + -- Put a 32-bit big-endian length for the utf8 string, in bytes. putInt32be $ byteLength stringbuf putArrayBuffer stringbuf -do - arraybuffer :: ArrayBuffer <- execPut $ putStringUtf8 "BLM" +arraybuffer :: ArrayBuffer <- execPut $ putStringUtf8 "🦝" ``` ### Serialize an `Array Int` @@ -85,7 +86,7 @@ import Data.Array (length) putArrayInt32 :: forall m. MonadEffect m => Array Int -> PutM m Unit putArrayInt32 xs = do - -- Put a 64-bit big-endian length prefix for the length of the array. + -- Put a 64-bit big-endian length prefix for the array. putInt32be 0 putInt32be $ length xs traverse_ putInt32be xs @@ -105,7 +106,7 @@ import Data.Array (foldRecM) putArrayInt32 :: forall m. MonadEffect m => MonadRec m => Array Int -> PutM m Unit putArrayInt32 xs = do - -- Put a 64-bit big-endian length prefix for the length of the array. + -- Put a 64-bit big-endian length prefix for the array. putInt32be 0 putInt32be $ length xs foldRecM (\_ x -> putInt32be x) unit xs @@ -129,6 +130,7 @@ for a way to deserialize from `ArrayBuffer` back to Purescript data. * [__node-buffer__](https://pursuit.purescript.org/packages/purescript-node-buffer) * [__arraybuffer-class__](https://pursuit.purescript.org/packages/purescript-arraybuffer-class) * [__bytestrings__](https://pursuit.purescript.org/packages/purescript-bytestrings/) +* [__array-builder__](https://pursuit.purescript.org/packages/purescript-array-builder) ## Development diff --git a/bower.json b/bower.json index e470594..ac032a6 100644 --- a/bower.json +++ b/bower.json @@ -14,7 +14,7 @@ "output" ], "dependencies": { - "purescript-arraybuffer": "^v13.0.0", + "purescript-arraybuffer": "^v13.1.1", "purescript-arraybuffer-types": "^v3.0.2", "purescript-effect": "^v4.0.0", "purescript-float32": "^v2.0.0", @@ -22,8 +22,8 @@ "purescript-lists": "^v7.0.0", "purescript-maybe": "^v6.0.0", "purescript-newtype": "^v5.0.0", - "purescript-prelude": "^v6.0.0", - "purescript-tailrec": "^v6.0.0", + "purescript-prelude": "^v6.0.1", + "purescript-tailrec": "^v6.1.0", "purescript-transformers": "^v6.0.0", "purescript-uint": "^v7.0.0" } diff --git a/packages.dhall b/packages.dhall index bd3ec92..8136147 100644 --- a/packages.dhall +++ b/packages.dhall @@ -117,8 +117,8 @@ let additions = ------------------------------- -} let upstream = - https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.0-20220502/src/packages.dhall - sha256:38d347aeba9fe6359c208abe87a5cecf1ffb14294f11ad19664ae35c59b6e29a + https://raw.githubusercontent.com/purescript/package-sets/psc-0.15.4-20221209/src/packages.dhall + sha256:b55c24bf585df4041ae6e87124cab7b35d474a9a77c9c3862ee6bf1dae618d72 let overrides = {=} diff --git a/spago-dev.dhall b/spago-dev.dhall index 18f1625..2a86ff6 100644 --- a/spago-dev.dhall +++ b/spago-dev.dhall @@ -15,5 +15,6 @@ in conf // , dependencies = conf.dependencies # [ "assert" , "arrays" + , "web-encoding" ] } diff --git a/src/Data/ArrayBuffer/Builder.purs b/src/Data/ArrayBuffer/Builder.purs index 26ba03a..d363bc6 100644 --- a/src/Data/ArrayBuffer/Builder.purs +++ b/src/Data/ArrayBuffer/Builder.purs @@ -5,10 +5,10 @@ -- | Writing to an `ArrayBuffer` is an `Effect`ful activity, so most -- | functions in this module must be run in a `MonadEffect` context. -- | --- | For operations for working with `ArrayBuffer`, see +-- | For other operations for working with `ArrayBuffer`, see -- | module -- | [`Data.ArrayBuffer.ArrayBuffer`](https://pursuit.purescript.org/packages/purescript-arraybuffer/docs/Data.ArrayBuffer.ArrayBuffer) --- | in package __purescript-arraybuffer__. +-- | in package __arraybuffer__. module Data.ArrayBuffer.Builder ( PutM , Put diff --git a/test/Main.purs b/test/Main.purs index ac5021d..3b13bdf 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -5,14 +5,20 @@ import Prelude import Control.Monad.Writer.Trans (tell) import Data.Array (foldRecM) import Data.Array as Array -import Data.ArrayBuffer.Builder (Builder, DataBuff(..), PutM, execPut, putInt16be, putInt32le, putInt8, subBuilder) +import Data.ArrayBuffer.ArrayBuffer (byteLength) +import Data.ArrayBuffer.Builder (Builder, DataBuff(..), PutM, execPut, putArrayBuffer, putInt16be, putInt32be, putInt32le, putInt8, subBuilder) import Data.ArrayBuffer.Builder.Internal (cons, encodeInt8, execBuilder, length, singleton, (<>>)) import Data.ArrayBuffer.DataView as DV +import Data.ArrayBuffer.Typed (buffer) import Data.ArrayBuffer.Typed as AT -import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array) +import Data.ArrayBuffer.Typed as AV +import Data.ArrayBuffer.Types (ArrayBuffer, Uint8Array, Int8Array) import Data.UInt as UInt import Effect (Effect) +import Effect.Class (class MonadEffect, liftEffect) import Test.Assert (assertEqual') +import Web.Encoding.TextEncoder (encode) +import Web.Encoding.TextEncoder as TextEncoder asBytes :: ArrayBuffer -> Effect (Array Int) asBytes x = do @@ -120,3 +126,21 @@ main = do let stackblower = Array.replicate 20000 2 putTest "Stack test" stackblower do foldRecM (\_ x -> putInt8 x) unit stackblower + + do + let + putStringUtf8 :: forall m. MonadEffect m => String -> PutM m Unit + putStringUtf8 s = do + textEncoder <- liftEffect TextEncoder.new + let stringbuf = buffer $ encode s textEncoder + -- Put a 32-bit big-endian length prefix for the length of the utf8 string, in bytes. + putInt32be $ byteLength stringbuf + putArrayBuffer stringbuf + + arraybuffer :: ArrayBuffer <- execPut $ putStringUtf8 "🦝" + view :: Int8Array <- AV.whole arraybuffer + viewarray <- AV.toArray view + assertEqual' "utf-8 test" + { actual: viewarray + , expected: [ 0, 0, 0, 4, -16, -97, -90, -99 ] + }