{"id":18355379,"url":"https://github.com/charto/cpak","last_synced_at":"2025-04-10T01:37:23.280Z","repository":{"id":88491836,"uuid":"106447910","full_name":"charto/cpak","owner":"charto","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-05T07:42:33.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T00:35:11.730Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/charto.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-10T17:16:11.000Z","updated_at":"2017-10-10T17:16:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"7af0a7c4-1f53-40ba-86ee-275a512b247b","html_url":"https://github.com/charto/cpak","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"f8ca1cb1a29881e3425c3942ad609578dca6361f"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charto%2Fcpak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charto%2Fcpak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charto%2Fcpak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charto%2Fcpak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charto","download_url":"https://codeload.github.com/charto/cpak/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248141388,"owners_count":21054446,"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":[],"created_at":"2024-11-05T22:06:42.739Z","updated_at":"2025-04-10T01:37:23.261Z","avatar_url":"https://github.com/charto.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"cpak\n====\n\n[![npm version](https://img.shields.io/npm/v/cpak.svg)](https://www.npmjs.com/package/cpak)\n\n`cpak` is a compressed data format for numeric data, embeddable in code and\ntext documents. It's especially suitable for geometry and geographic data.\n\nThis package contains the spec (soon) and some supporting functions.\nFor reading and writing geographic data, use (for example)\n[cgeo-cpak](https://github.com/charto/cgeo-cpak)\n\nThe specification consists of multiple levels:\n\n- Level 0: Suitable for any numeric data. Necessary JavaScript code (and no more)\n  is included in this package.\n- Level 1: Defines an encoding for SQL/MM Spatial data types. Additional convention or\n  configuration is required to represent WKB and WKT data.\n- Level 2 (future): Full replacement for WKB and WKT.\n\nLevel 0\n-------\n\nUnsigned integers are encoded using the 92 printable non-whitespace ASCII\ncharacters that survive unchanged through `JSON.stringify`. These form 2 groups\ncontaining 64 and 28 characters, used as \"digits\" in base 64 or 28.\n\nSigned integers are zigzag encoded first, in the same way as protocol buffers:\n\n```TypeScript\nunsigned = (signed \u003c\u003c 1) ^ (signed \u003e\u003e 31);\nsigned = (unsigned \u003e\u003e\u003e 1) ^ -(unsigned \u0026 1);\n```\n\nDigits are stored most significant first, and the last digit always comes from\na different group than any preceding ones, to distinguish where the next number\nbegins.\n\nNumbers expected to be smaller than 64 use the 64-character group for their\nlast \"digit\". That allows usually storing them in one byte. Larger numbers use\nthe 28-character group for their last \"digit\" and 64-character group for the\nother digits. That allows usually storing them in the same amount of space that\nBase64 would take.\n\nCharacters left unused due to incompatibility with JSON are `\"` and `\\` (ASCII\n34 and 92). It turns out the following formulas convert between digits and\nASCII characters without requiring lookup tables:\n\n```TypeScript\nascii = digit + (((digit + 1934) * 9) \u003e\u003e 9);\ndigit = ascii - (((ascii + 1900) * 9) \u003e\u003e 9);\n```\n\nThe same code works at least in JavaScript, C and C++. All those languages also\nsupport string literals with `cpak` encoded data as-is.\n\n`digit` is a number between 0-91, where 0-63 forms one group and 64-91 is the\nother. `ascii` is a character code from the following string, indexed by `digit`:\n\n```text\n!#$%\u0026'()*+,-./0123456789:;\u003c=\u003e?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~\n```\n\nLevel 1\n-------\n\nEncoding is similar to WKB (Well-Known Binary) with endianness flags omitted\nand all integers stored in a variable-length format.\n\nGeometry type IDs are multiplied by 2 compared to WKB. This allows the least\nsignificant bit to indicate spec level.\n\n- 0 means level 1.\n- 1 means level 2 (or higher).\n\nFloating point values need to be rounded to integers before encoding.\nMultiplying them by some factor first allows keeping fractional digits\nup to a desired precision. Powers of 2 and 10 both have their advantages\nwhen choosing a multiplication factor:\n\n- Base 2 allows easy further lossless conversion to WKB or shapefiles and back.\n- Base 10 allows easy further lossless conversion to WKT or GeoJSON and back.\n\nThe same multiplication factor must be used when reading and writing,\nand level 1 leaves it to the application to guarantee this. Embedding\ncpak-encoded geometry into JSON is the recommended way to allow storing\nadditional metadata.\n\nLicense\n=======\n\nDual-licensed under:\n\n[The MIT License](https://raw.githubusercontent.com/charto/cpak/master/LICENSE)\n\n[![CC0](http://i.creativecommons.org/p/zero/1.0/88x31.png)](http://creativecommons.org/publicdomain/zero/1.0/)\n\nCopyright (c) 2017 BusFaster Ltd\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharto%2Fcpak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharto%2Fcpak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharto%2Fcpak/lists"}