{"id":13800545,"url":"https://github.com/rowtype-yoga/purescript-arraybuffer-builder","last_synced_at":"2026-01-18T17:33:54.329Z","repository":{"id":40538347,"uuid":"279579800","full_name":"rowtype-yoga/purescript-arraybuffer-builder","owner":"rowtype-yoga","description":"ArrayBuffer builder for Purescript","archived":false,"fork":false,"pushed_at":"2023-05-17T15:22:05.000Z","size":65,"stargazers_count":7,"open_issues_count":6,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-11T15:23:12.776Z","etag":null,"topics":["arraybuffer","purescript"],"latest_commit_sha":null,"homepage":"https://pursuit.purescript.org/packages/purescript-arraybuffer-builder","language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rowtype-yoga.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-07-14T12:32:21.000Z","updated_at":"2024-02-04T15:15:51.000Z","dependencies_parsed_at":"2024-01-30T04:13:09.767Z","dependency_job_id":null,"html_url":"https://github.com/rowtype-yoga/purescript-arraybuffer-builder","commit_stats":null,"previous_names":["jamesdbrock/purescript-arraybuffer-builder"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/rowtype-yoga/purescript-arraybuffer-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowtype-yoga%2Fpurescript-arraybuffer-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowtype-yoga%2Fpurescript-arraybuffer-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowtype-yoga%2Fpurescript-arraybuffer-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowtype-yoga%2Fpurescript-arraybuffer-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rowtype-yoga","download_url":"https://codeload.github.com/rowtype-yoga/purescript-arraybuffer-builder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowtype-yoga%2Fpurescript-arraybuffer-builder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28544923,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T14:59:57.589Z","status":"ssl_error","status_checked_at":"2026-01-18T14:59:46.540Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arraybuffer","purescript"],"created_at":"2024-08-04T00:01:13.607Z","updated_at":"2026-01-18T17:33:54.311Z","avatar_url":"https://github.com/rowtype-yoga.png","language":"PureScript","readme":"# purescript-arraybuffer-builder\n\n[![CI](https://github.com/rowtype-yoga/purescript-arraybuffer-builder/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-arraybuffer-builder/actions)\n[![Pursuit](http://pursuit.purescript.org/packages/purescript-arraybuffer-builder/badge)](http://pursuit.purescript.org/packages/purescript-arraybuffer-builder/)\n[![Maintainer: jamesdbrock](https://img.shields.io/badge/maintainer-jamesdbrock-teal.svg)](https://github.com/jamesdbrock)\n\n\n[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)\nserialization in the “builder monoid” and “builder monad” style.\nIn this style, we build up serialized data structures by `tell`ing to\na `Writer` monad with `do`-notation. This style of serialization\nhas been used for a long time and we [insist that it works really well](https://wiki.haskell.org/Do_notation_considered_harmful#Library_design).\n\nThis package provides a `Builder` monoid and a `PutM` monad which are roughly\nequivalent to types of the same name in the Haskell\n[__Data.Binary.Put__](https://hackage.haskell.org/package/binary/docs/Data-Binary-Put.html)\nmodule.\n\n## Usage Examples\n\nAll `ArrayBuffer` building must occur in `Effect`.\n\n### Serialize an integer\n\nCreate a two-byte `arraybuffer :: ArrayBuffer` which contains the number *-10* encoded as big-endian 16-bit two’s-complement.\n```purescript\nimport Data.ArrayBuffer.Builder (execPut, putInt16be)\n\ndo\n  arraybuffer :: ArrayBuffer \u003c- execPut $ putInt16be (-10)\n```\n\n### Serialize three floats\n\nCreate a 24-byte `arraybuffer :: ArrayBuffer` which contains three big-endian\nIEEE-754 double-precision floats.\n\n```purescript\nimport Data.ArrayBuffer.Builder (execPut, putFloat64be)\n\ndo\n  arraybuffer :: ArrayBuffer \u003c- execPut do\n    putFloat64be 1.0\n    putFloat64be 2.0\n    putFloat64be 3.0\n```\n\n### Serialize a `String` as UTF8\n\nEncode a `String` as UTF8 with a length prefix into our `Builder`.\n\nWe give this as an example, rather than supporting it in the library, because\nit depends on\n[`Web.Encoding.TextEncoder`](https://pursuit.purescript.org/packages/purescript-web-encoding/docs/Web.Encoding.TextEncoder).\n\n```purescript\nimport Effect.Class (class MonadEffect, liftEffect)\nimport Data.UInt (fromInt)\nimport Data.ArrayBuffer.Types (ArrayBuffer(..))\nimport Data.ArrayBuffer.Builder (PutM, putArrayBuffer, execPut, putUint32be)\nimport Data.ArrayBuffer.Typed (buffer)\nimport Data.ArrayBuffer.ArrayBuffer (byteLength)\nimport Web.Encoding.TextEncoder (new, TextEncoder, encode)\n\nputStringUtf8 :: forall m. MonadEffect m =\u003e String -\u003e PutM m Unit\nputStringUtf8 s = do\n  textEncoder \u003c- liftEffect new\n  let stringbuf = buffer $ encode s textEncoder\n  -- Put a 32-bit big-endian length for the utf8 string, in bytes.\n  putUint32be $ fromInt $ byteLength stringbuf\n  putArrayBuffer stringbuf\n\narraybuffer :: ArrayBuffer \u003c- execPut $ putStringUtf8 \"🦝\"\n```\n\n### Serialize an `Array Int`\n\nEncode an `Array Int` with a length prefix in a\nway that's compatible with the\n[`Binary` instance for `[Int32]`](https://hackage.haskell.org/package/binary/docs/Data-Binary.html#t:Binary)\nfrom the Haskell\n[__binary__](https://hackage.haskell.org/package/binary)\nlibrary.\n\n```purescript\nimport Data.ArrayBuffer.Builder (execPut, putInt32be)\nimport Data.Foldable (traverse_)\nimport Data.Array (length)\n\nputArrayInt32 :: forall m. MonadEffect m =\u003e Array Int -\u003e PutM m Unit\nputArrayInt32 xs = do\n    -- Put a 64-bit big-endian length prefix for the array.\n    putInt32be 0\n    putInt32be $ length xs\n    traverse_ putInt32be xs\n\ndo\n  arraybuffer \u003c- execPut $ putArrayInt32 [1,2,3]\n```\n\n### Serialize an `Array Int` stack-safe\n\nStack-safe version of the `putArrayInt32` function above. For stack-safety\nwe use `foldRecM` instead of `traverse_` because `foldRecM` has a `MonadRec`\nconstraint which makes it stack-safe.\n\n```purescript\nimport Data.Array (foldRecM)\n\nputArrayInt32 :: forall m. MonadEffect m =\u003e MonadRec m =\u003e Array Int -\u003e PutM m Unit\nputArrayInt32 xs = do\n    -- Put a 64-bit big-endian length prefix for the array.\n    putInt32be 0\n    putInt32be $ length xs\n    foldRecM (\\_ x -\u003e putInt32be x) unit xs\n```\n\n## Stack-safety\n\nThis package will always be stack-safe if all of the functions called inside\nof the `PutM` builder expression are stack-safe.\n\n## Deserialization\n\nThis package is only for writing `ArrayBuffer`s, not reading them.\nSee\n[__parsing-dataview__](https://pursuit.purescript.org/packages/purescript-parsing-dataview/)\nfor a way to deserialize from `ArrayBuffer` back to Purescript data.\n\n## Alternative packages for serializing to an `ArrayBuffer`\n\n* [__dynamic-buffers__](https://pursuit.purescript.org/packages/purescript-dynamic-buffers)\n* [__node-buffer__](https://pursuit.purescript.org/packages/purescript-node-buffer)\n* [__arraybuffer-class__](https://pursuit.purescript.org/packages/purescript-arraybuffer-class)\n* [__bytestrings__](https://pursuit.purescript.org/packages/purescript-bytestrings/)\n* [__array-builder__](https://pursuit.purescript.org/packages/purescript-array-builder)\n\n## Development\n\nTo run the tests,\n\n```shell\nspago -x spago-dev.dhall test\n```\n","funding_links":[],"categories":["Binary Serialization"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowtype-yoga%2Fpurescript-arraybuffer-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frowtype-yoga%2Fpurescript-arraybuffer-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowtype-yoga%2Fpurescript-arraybuffer-builder/lists"}