{"id":13414713,"url":"https://github.com/webtorrent/node-bencode","last_synced_at":"2025-07-04T22:10:15.003Z","repository":{"id":976571,"uuid":"775875","full_name":"webtorrent/node-bencode","owner":"webtorrent","description":"bencode de/encoder for nodejs","archived":false,"fork":false,"pushed_at":"2024-04-10T23:39:21.000Z","size":572,"stargazers_count":161,"open_issues_count":18,"forks_count":36,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-01T11:41:24.345Z","etag":null,"topics":["abstract-encoding","bencode","bittorrent","javascript","webtorrent"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/webtorrent.png","metadata":{"funding":{"github":["webtorrent","feross"]},"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2010-07-15T02:25:04.000Z","updated_at":"2024-05-11T20:29:17.868Z","dependencies_parsed_at":"2023-07-05T18:31:53.105Z","dependency_job_id":"3f9fecda-d472-4baa-a3f7-be24c8fa9cd8","html_url":"https://github.com/webtorrent/node-bencode","commit_stats":{"total_commits":262,"total_committers":25,"mean_commits":10.48,"dds":0.7900763358778626,"last_synced_commit":"2fa2c7ea7d97791a0c7f0cb3dd0bb098c014738f"},"previous_names":["themasch/node-bencode"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fnode-bencode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fnode-bencode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fnode-bencode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webtorrent%2Fnode-bencode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webtorrent","download_url":"https://codeload.github.com/webtorrent/node-bencode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221513932,"owners_count":16835746,"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":["abstract-encoding","bencode","bittorrent","javascript","webtorrent"],"created_at":"2024-07-30T21:00:33.612Z","updated_at":"2024-10-26T08:30:23.051Z","avatar_url":"https://github.com/webtorrent.png","language":"JavaScript","readme":"# Bencode\n[![npm](https://img.shields.io/npm/v/bencode.svg)](https://npmjs.com/bencode)\n[![npm downloads](https://img.shields.io/npm/dm/bencode.svg)](https://npmjs.com/bencode)\n[![ci](https://github.com/webtorrent/node-bencode/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/webtorrent/node-bencode/actions/workflows/ci.yml)\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fwebtorrent%2Fnode-bencode.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fwebtorrent%2Fnode-bencode?ref=badge_shield)\n\nA node library for encoding and decoding bencoded data,\naccording to the [BitTorrent specification](http://www.bittorrent.org/beps/bep_0003.html).\n\n## Index\n\n- [About BEncoding](#about-bencoding)\n- [Installation](#install-with-npm)\n- [Usage](#usage)\n- [API](#api)\n\n## About BEncoding\n\nfrom [Wikipedia](https://en.wikipedia.org/wiki/Bencoding):\n\nBencode (pronounced like B encode) is the encoding used by the peer-to-peer\nfile sharing system BitTorrent for storing and transmitting loosely structured data.\n\nIt supports four different types of values:\n- byte strings\n- integers\n- lists\n- dictionaries\n\nBencoding is most commonly used in torrent files.\nThese metadata files are simply bencoded dictionaries.\n\n## Install with [npm](https://npmjs.org)\n\n```\nnpm install bencode\n```\n\n## Usage\n\n```javascript\nimport bencode from 'bencode'\n```\n\nYou can also use node-bencode with browserify to be able to use it in a lot of modern browsers.\n\n### Encoding\n\n```javascript\n\nvar data = {\n  string: 'Hello World',\n  integer: 12345,\n  dict: {\n    key: 'This is a string within a dictionary'\n  },\n  list: [ 1, 2, 3, 4, 'string', 5, {} ]\n}\n\nvar result = bencode.encode( data )\n\n```\n\n**NOTE** As of `bencode@0.8.0`, boolean values will be cast to integers (false -\u003e 0, true -\u003e 1).\n\n#### Output\n\n```\nd4:dictd3:key36:This is a string within a dictionarye7:integeri12345e4:listli1ei2ei3ei4e6:stringi5edee6:string11:Hello Worlde\n```\n\n### Decoding\n\n```javascript\nvar data = Buffer.from('d6:string11:Hello World7:integeri12345e4:dictd3:key36:This is a string within a dictionarye4:listli1ei2ei3ei4e6:stringi5edeee')\nvar result = bencode.decode( data )\n```\n\n#### Output\n\n```javascript\n{\n  string: \u003cBuffer 48 65 6c 6c 6f 20 57 6f 72 6c 64\u003e,\n  integer: 12345,\n  dict: {\n    key: \u003cBuffer 54 68 69 73 20 69 73 20 61 20 73 74 72 69 6e 67 20 77 69 74 68 69 6e 20 61 20 64 69 63 74 69 6f 6e 61 72 79\u003e\n  },\n  list: [ 1, 2, 3, 4, \u003cBuffer 73 74 72 69 6e 67\u003e, 5, {} ]\n}\n```\n\nAutomagically convert bytestrings to strings:\n\n```javascript\nvar result = bencode.decode( data, 'utf8' )\n```\n\n#### Output\n\n```javascript\n{\n  string: 'Hello World',\n  integer: 12345,\n  dict: {\n    key: 'This is a string within a dictionary'\n  },\n  list: [ 1, 2, 3, 4, 'string', 5, {} ]\n}\n```\n\n## API\n\nThe API is compatible with the [`abstract-encoding`](https://github.com/mafintosh/abstract-encoding) specification.\n\n### bencode.encode( *data*, *[buffer]*, *[offset]* )\n\n\u003e `Buffer` | `Array` | `String` | `Object` | `Number` | `Boolean` __data__\n\u003e `Buffer` __buffer__\n\u003e `Number` __offset__\n\nReturns `Buffer`\n\n### bencode.decode( *data*, *[start]*, *[end]*, *[encoding]* )\n\n\u003e `Buffer` __data__\n\u003e `Number` __start__\n\u003e `Number` __end__\n\u003e `String` __encoding__\n\nIf `encoding` is set, bytestrings are\nautomatically converted to strings.\n\nReturns `Object` | `Array` | `Buffer` | `String` | `Number`\n\n### bencode.byteLength( *value* ) or bencode.encodingLength( *value* )\n\n\u003e `Buffer` | `Array` | `String` | `Object` | `Number` | `Boolean` __value__\n","funding_links":["https://github.com/sponsors/webtorrent","https://github.com/sponsors/feross"],"categories":["Protocols","JavaScript"],"sub_categories":["BitTorrent"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebtorrent%2Fnode-bencode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebtorrent%2Fnode-bencode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebtorrent%2Fnode-bencode/lists"}