{"id":20234508,"url":"https://github.com/adaxi/bencode","last_synced_at":"2025-03-03T14:12:54.661Z","repository":{"id":57715074,"uuid":"61659173","full_name":"adaxi/Bencode","owner":"adaxi","description":"Encode and decode B-encoded content","archived":false,"fork":false,"pushed_at":"2017-03-19T19:13:41.000Z","size":86,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-14T00:34:47.877Z","etag":null,"topics":["bencode","java","torrent"],"latest_commit_sha":null,"homepage":"","language":"Java","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/adaxi.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":"2016-06-21T18:56:21.000Z","updated_at":"2024-12-09T19:54:21.000Z","dependencies_parsed_at":"2022-08-31T02:41:13.629Z","dependency_job_id":null,"html_url":"https://github.com/adaxi/Bencode","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/adaxi%2FBencode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adaxi%2FBencode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adaxi%2FBencode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adaxi%2FBencode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adaxi","download_url":"https://codeload.github.com/adaxi/Bencode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241678157,"owners_count":20001682,"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":["bencode","java","torrent"],"created_at":"2024-11-14T08:11:07.119Z","updated_at":"2025-03-03T14:12:54.628Z","avatar_url":"https://github.com/adaxi.png","language":"Java","readme":"B-Encode\n========\n\n[![Build Status](https://travis-ci.org/adaxi/Bencode.svg?branch=master)](https://travis-ci.org/adaxi/Bencode) [![Coverage Status](https://coveralls.io/repos/github/adaxi/Bencode/badge.svg?branch=master)](https://coveralls.io/github/adaxi/Bencode?branch=master) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/be.adaxisoft/Bencode/badge.svg)](http://adaxi.github.io/Bencode/dependency-info.html)\n\nThis library allows you to encode and decode B-encoded documents.\n\nBefore:\n\n```java\nMap\u003cString,BEncodedValue\u003e document = new HashMap\u003cString, BEncodedValue\u003e() {{\n    put(\"string\", new BEncodedValue(\"value\"));\n    put(\"number\", new BEncodedValue(123456));\n    put(\"list\", new BEncodedValue(new ArrayList\u003cBEncodedValue\u003e() {{\n        add(new BEncodedValue(\"list-item-1\"));\n        add(new BEncodedValue(\"list-item-2\"));\n    }}));\n    put(\"dict\", new BEncodedValue(new HashMap\u003cString, BEncodedValue\u003e() {{\n        put(\"123\", new BEncodedValue(\"test\"));\n        put(\"456\", new BEncodedValue(\"thing\"));\n    }}));\n}};\n\nByteArrayOutputStream baos = new ByteArrayOutputStream();\nBEncoder.encode(document, baos);\nString encodedDocument = new String(baos.toByteArray());\n```\n\nAfter:\n\n```\nd\n\t4:dict\t\td\n\t\t\t\t\t3:123\t4:test\n\t\t\t\t\t3:456\t5:thing\n\t\t\t\te\n\t4:list\t\tl\n\t\t\t\t\t11:list-item-1\n\t\t\t\t\t11:list-item-2\n\t\t\t\te\n\t6:number\ti123456e\n\t6:string\t5:value\ne\n```\n\nThe library can do the reverse operation as well: decode.\n\nI want to decode a torrent file. How can I do that?\n---------------------------------------------------\n\nFirst you need to read the torrent and decode it:\n\n```java\nFile torrentFile = \"file.torrent\";\nFileInputStream inputStream = new FileInputStream(torrentFile);\nBDecoder reader = new BDecoder(inputStream);\nMap\u003cString, BEncodedValue\u003e document = reader.decodeMap().getMap();\n```\n\nThen you can start extracting information from it:\n\n```java\nString announce = document.get(\"announce\").getString(); // Strings\nMap\u003cString, BEncodedValue\u003e info = document.get(\"info\").getMap(); // Maps\nList\u003cBEncodedValue\u003e files = info.get(\"files\").getList(); // Lists\n```\n\nYou can check if a key exists using the 'containsKey' method as such:\n\n```java\nif (document.containsKey(\"info\")) {\n    System.out.println(\"The info field exists\");\n}\n```\n\nUse the library\n--------------\n\nThe [documentation page](http://adaxi.github.io/Bencode/dependency-info.html) lists how you can add this library\nas a dependency of your project.\n\nCredit\n------\n\nThis library was created since no other viable libraries existed, and the ttorrent\nproject contains a bunch of unecessary content. It is based on the work of [Maxime Petazzoni](https://github.com/mpetazzoni/ttorrent).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadaxi%2Fbencode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadaxi%2Fbencode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadaxi%2Fbencode/lists"}