{"id":21304761,"url":"https://github.com/nrepl/bencode","last_synced_at":"2025-04-06T08:14:32.172Z","repository":{"id":41092736,"uuid":"136301860","full_name":"nrepl/bencode","owner":"nrepl","description":"A netstring and bencode implementation for Clojure.","archived":false,"fork":false,"pushed_at":"2024-06-12T15:20:11.000Z","size":50,"stargazers_count":50,"open_issues_count":1,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-29T23:59:56.720Z","etag":null,"topics":["bencode","clojure","netstrings","nrepl"],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nrepl.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":"2018-06-06T09:00:42.000Z","updated_at":"2024-06-12T15:20:15.000Z","dependencies_parsed_at":"2024-11-07T19:35:23.537Z","dependency_job_id":"26a7fde5-d62e-470d-aeb9-e5902b539438","html_url":"https://github.com/nrepl/bencode","commit_stats":{"total_commits":33,"total_committers":9,"mean_commits":"3.6666666666666665","dds":0.4242424242424242,"last_synced_commit":"ba56b9cc9313d35292892995d1889743ffd8aeb7"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrepl%2Fbencode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrepl%2Fbencode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrepl%2Fbencode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nrepl%2Fbencode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nrepl","download_url":"https://codeload.github.com/nrepl/bencode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247168304,"owners_count":20895088,"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","clojure","netstrings","nrepl"],"created_at":"2024-11-21T16:15:52.868Z","updated_at":"2025-04-06T08:14:32.154Z","avatar_url":"https://github.com/nrepl.png","language":"Clojure","readme":"[![CircleCI](https://circleci.com/gh/nrepl/bencode/tree/master.svg?style=svg)](https://circleci.com/gh/nrepl/bencode/tree/master)\n[![Clojars Project](https://img.shields.io/clojars/v/nrepl/bencode.svg)](https://clojars.org/nrepl/bencode)\n[![cljdoc badge](https://cljdoc.org/badge/nrepl/bencode)](https://cljdoc.org/d/nrepl/bencode/CURRENT)\n[![downloads badge](https://versions.deps.co/nrepl/bencode/downloads.svg)](https://clojars.org/nrepl/bencode)\n\n# bencode\n\nA netstring and bencode implementation for Clojure.\n\nThis particular implementation was extracted from [nREPL][], so it\ncould be reused by other applications.\n\n[nREPL]: https://nrepl.org\n\nThere are other netstring/bencode libraries for Clojure out there, but this one has\nthe distinct advantage that it's certainly going to work well with nREPL. ;-)\n\n**P.S.** It's also very fast and very memory efficient, but who's counting! :D\n\n## Motivation\n\nIn each and every application, which contacts peer processes via some\ncommunication channel, the handling of the communication channel is\nobviously a central part of the application. Unfortunately introduces\nhandling of buffers of varying sizes often bugs in form of buffer\noverflows and similar.\n\nA strong factor in this situation is of course the protocol which goes\nover the wire. Depending on its design it might be difficult to estimate\nthe size of the input up front. This introduces more handling of message\nbuffers to accomodate for inputs of varying sizes. This is particularly\ndifficult in languages like C, where there is no bounds checking of array\naccesses and where errors might go unnoticed for considerable amount of\ntime.\n\nTo address these issues D. Bernstein developed the so called\n[netstrings][net]. They are especially designed to allow easy construction\nof the message buffers, easy and robust parsing.\n\nBitTorrent extended this to the [bencode][bc] protocol which also\nincludes ways to encode numbers and collections like lists or maps.\n\n*wire* is based on these ideas.\n\n[net]: http://cr.yp.to/proto/netstrings.txt\n[bc]:  http://wiki.theory.org/BitTorrentSpecification#Bencoding\n\n## Usage\n\nJust add `bencode` as a dependency to your project and start hacking.\n\n```clojure\n[nrepl/bencode \"1.2.0\"]\n```\n\nThe API is documented in great detail [here](https://github.com/nrepl/bencode/blob/master/src/bencode/core.clj).\n\nThe main functions in the API are:\n\n* `read-netstring`\n* `write-nestring`\n* `read-bencode`\n* `write-bencode`\n\nHere are some usage examples for each of the functions available:\n\n- `read-netstring`\n\n ```clojure\n (-\u003e (.getBytes \"13:Hello, World!,\" \"UTF-8\")\n     ByteArrayInputStream.\n     read-netstring\n     (String. \"UTF-8\"))\n\n =\u003e Hello, World!\n ```\n\n- `write-netstring`\n\n ```clojure\n (-\u003e (doto (ByteArrayOutputStream.)\n        (write-netstring (.getBytes \"Hello, World!\" \"UTF-8\")))\n     .toString)\n\n =\u003e \"13:Hello, World!,\"\n ```\n\n- `read-bencode`\n\n ```clojure\n (vec\n   (map\n     #(String. % \"UTF-8\")\n     (-\u003e (.getBytes \"5:nrepl2:is7:awesomee\" \"UTF-8\")\n         ByteArrayInputStream.\n         PushbackInputStream.\n         read-bencode)))\n\n=\u003e [\"nrepl\" \"is\" \"awesome\"]\n ```\n\n- `write-bencode`\n\n ```clojure\n(-\u003e (doto (ByteArrayOutputStream.)\n      (write-bencode {:foo \"bar\"}))\n    .toString)\n\n=\u003e \"d3:foo3:bare\"\n ```\n\nAdditionally, you can check this [document](https://github.com/nrepl/nrepl/blob/master/test/clojure/nrepl/bencode_test.clj) to learn more about its usage.\n\n## Use Cases\n\nObviously you can use this library whenever you need to deal with netstrings or\nbencode, but I assume that in practice most people will end up using it for\nbuilding alternative Clojure nREPL clients or\nservers. [babashka.nrepl](https://github.com/babashka/babashka.nrepl) is one\nnotable user of the library.\n\nThere's also the potential to have the library support ClojureScript and\nClojureCLR down the road, so it could be leveraged in even more\ncontexts. Sky is the limit!\n\n## License\n\nCopyright © 2018-2024 Meikel Brandmeyer, Oleksandr Yakushev, Bozhidar Batsov and nREPL contributors\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrepl%2Fbencode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnrepl%2Fbencode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnrepl%2Fbencode/lists"}