{"id":14384399,"url":"https://github.com/ipld/js-dag-cbor","last_synced_at":"2025-04-04T07:08:17.866Z","repository":{"id":37893139,"uuid":"263230468","full_name":"ipld/js-dag-cbor","owner":"ipld","description":"dag-cbor codec for IPLD","archived":false,"fork":false,"pushed_at":"2025-03-24T09:25:44.000Z","size":307,"stargazers_count":31,"open_issues_count":3,"forks_count":17,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-28T06:08:39.735Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipld.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-05-12T04:17:12.000Z","updated_at":"2024-12-25T21:32:19.000Z","dependencies_parsed_at":"2024-02-16T11:32:43.422Z","dependency_job_id":"f525ec8a-91df-447c-a1ee-249f9770c421","html_url":"https://github.com/ipld/js-dag-cbor","commit_stats":{"total_commits":334,"total_committers":29,"mean_commits":"11.517241379310345","dds":0.7095808383233533,"last_synced_commit":"ee8c3327aed346a1d8d10a6aadff15b5a568ba97"},"previous_names":[],"tags_count":97,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Fjs-dag-cbor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Fjs-dag-cbor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Fjs-dag-cbor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipld%2Fjs-dag-cbor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipld","download_url":"https://codeload.github.com/ipld/js-dag-cbor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135144,"owners_count":20889421,"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-08-28T18:01:21.530Z","updated_at":"2025-04-04T07:08:17.834Z","avatar_url":"https://github.com/ipld.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# @ipld/dag-cbor \u003c!-- omit in toc --\u003e\n\n[![codecov](https://img.shields.io/codecov/c/github/ipld/js-dag-cbor.svg?style=flat-square)](https://codecov.io/gh/ipld/js-dag-cbor)\n[![CI](https://img.shields.io/github/workflow/status/ipld/js-dag-cbor/test%20\u0026%20maybe%20release/master?style=flat-square)](https://github.com/ipld/js-dag-cbor/actions/workflows/js-test-and-release.yml)\n\n\u003e JS implementation of DAG-CBOR\n\n## Table of contents \u003c!-- omit in toc --\u003e\n\n- [Install](#install)\n- [Spec](#spec)\n- [License](#license)\n- [Contribute](#contribute)\n\n## Install\n\n```console\n$ npm i @ipld/dag-cbor\n```\n\nThis is the *new* interface meant for use by itself or with `multiformats` and\n`@ipld/block`. It is not used by `js-ipld-format` which is currently\nused in IPFS. That library is [here](https://github.com/ipld/js-ipld-dag-cbor).\n\nUsage:\n\n```javascript\nimport { encode, decode } from '@ipld/dag-cbor'\nimport { CID } from 'multiformats'\n\nconst obj = {\n  x: 1,\n  /* CID instances are encoded as links */\n  y: [2, 3, CID.parse('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4')],\n  z: {\n    a: CID.parse('QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4'),\n    b: null,\n    c: 'string'\n  }\n}\n\nlet data = encode(obj)\nlet decoded = decode(data)\ndecoded.y[0] // 2\nCID.asCID(decoded.z.a) // cid instance\n\n// encode/decode options are exported for use with cborg's encodedLength and decodeFirst\nimport { encodeOptions, decodeOptions } from '@ipld/dag-cbor'\nimport { encodedLength } from 'cborg/length'\nimport { decodeFirst } from 'cborg'\n\n// dag-cbor encoded length of obj in bytes\nconst byteLength = encodedLength(obj, encodeOptions)\nbyteLength // 104\n\n// concatenate two dag-cbor encoded obj\nconst concatenatedData = new Uint8Array(data.length * 2)\nconcatenatedData.set(data)\nconcatenatedData.set(data, data.length)\n\n// returns dag-cbor decoded obj at the beginning of the buffer as well as the remaining bytes\nconst [first, remainder] = decodeFirst(concatenatedData, decodeOptions)\nassert.deepStrictEqual(first, obj)\nassert.deepStrictEqual(remainder, data)\n```\n\n## Spec\n\nThe [`dag-cbor` specification is in the IPLD specs repo](https://github.com/ipld/specs/blob/master/block-layer/codecs/dag-cbor.md).\n\n## License\n\nLicensed under either of\n\n- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n- MIT ([LICENSE-MIT](LICENSE-MIT) / \u003chttp://opensource.org/licenses/MIT\u003e)\n\n## Contribute\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipld%2Fjs-dag-cbor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipld%2Fjs-dag-cbor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipld%2Fjs-dag-cbor/lists"}