{"id":19746961,"url":"https://github.com/jordanbrauer/un-stow","last_synced_at":"2026-03-06T18:39:42.320Z","repository":{"id":57001402,"uuid":"195590145","full_name":"jordanbrauer/un-stow","owner":"jordanbrauer","description":"Offers a nice \u0026 powerful OOP and/or FP interface for PHP's `pack` and `unpack` functions.","archived":false,"fork":false,"pushed_at":"2019-10-14T21:28:32.000Z","size":72,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-28T14:09:33.421Z","etag":null,"topics":["binary","dependency-less","functional","library","micro","modern","object-oriented","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/jordanbrauer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-06T23:06:03.000Z","updated_at":"2021-11-30T08:18:54.000Z","dependencies_parsed_at":"2022-08-21T11:40:43.899Z","dependency_job_id":null,"html_url":"https://github.com/jordanbrauer/un-stow","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Fun-stow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Fun-stow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Fun-stow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jordanbrauer%2Fun-stow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jordanbrauer","download_url":"https://codeload.github.com/jordanbrauer/un-stow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224202777,"owners_count":17272807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["binary","dependency-less","functional","library","micro","modern","object-oriented","php"],"created_at":"2024-11-12T02:16:20.992Z","updated_at":"2026-03-06T18:39:42.272Z","avatar_url":"https://github.com/jordanbrauer.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (Un)Stow\n\nOffers a nice \u0026 powerful OOP and/or FP interface for PHP's `pack` and `unpack` functions.\n\n## Install\n\nInstall with Composer\n\n```bash\n$ composer require jordanbrauer/un-stow\n```\n\n## Examples\n\nBelow are a few basic examples of how to use this library.\n\n### Hello World\n\nSimple \"Hello World!\" example for packing (`stow`) and unpacking (`unstow`) hexadecimal data.\n\n```php\nstow('48656C6C6F20576F726C6421')-\u003ehexNibbleHigh('*')-\u003eclose();\n# = (string) Hello World!\n\nunstow('Hello World!')-\u003ehexNibbleHigh('*', 'hello_world')-\u003eopen();\n# = (array) [\n#     'hello_world' =\u003e 48656C6C6F20576F726C6421,\n# ],\n```\n\n### GIF Header\n\nEven though we have other methods of checking for GIF image data now, this serves as a good example of how `unstow` works for unpacking binary data to read headers.\n\n```php\n$stream = fopen('./tests/Portal.gif', 'rb');\n$bytes = fread($stream, 20);\n\nfclose($stream);\n\n$gifHeader = unstow($bytes)\n    -\u003espacePaddedString(6, 'version')\n    -\u003eunsignedChar(2, 'width')\n    -\u003eunsignedChar(2, 'height')\n    -\u003eunsignedChar(1, 'flag')\n    -\u003enullFill(11)\n    -\u003eunsignedChar(1, 'aspect')\n    -\u003eopen();\n```\n\n### Reusing Packers\n\nWith this library you are able to create \"template\" packers and unpackers which have a predefined pattern and can accept arbitrary data to pack/unpack.\n\n#### Object-Oriented Method\n\nTo re-use a packer in an OOP way, simply omit the bytes from your constructor and chain your format method calls to create your pattern. Next you can pass arbitrary data to the `load` method on and call `close`/`open` to process the data according to the format.\n\n_E.g._,\n\n```php\n$packer = stow()\n    -\u003eunsignedShort('', Stow::BIG_ENDIAN_16_BIT)\n    -\u003eunsignedShort('', Stow::LITTLE_ENDIAN_16_BIT)\n    -\u003esignedChar('*');\n\necho $packer-\u003eload(0x1234, 0x5678, 65, 66)-\u003eclose();\n```\n\n#### Functional Method\n\nThe functional method is quite similar to the object-oriented way, except two small differences.\n\n1. After chaining all your format method calls, finish it off by calling the `standby` method.\n    - This method will return a closure that accepts a set of variadic arguments of arbitrary data.\n2. No need to call the `open`/`close` methods: the closure simply returns the packed/unpacked data!\n\n_E.g._,\n\n```php\n$packer = stow()\n    -\u003eunsignedShort('', Stow::BIG_ENDIAN_16_BIT)\n    -\u003eunsignedShort('', Stow::LITTLE_ENDIAN_16_BIT)\n    -\u003esignedChar('*')\n    -\u003estandby();\n\necho $packer(0x1234, 0x5678, 65, 66);\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordanbrauer%2Fun-stow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjordanbrauer%2Fun-stow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjordanbrauer%2Fun-stow/lists"}