Skip to content

Instantly share code, notes, and snippets.

@victorb
Created November 3, 2020 17:00
Show Gist options
  • Select an option

  • Save victorb/dca8a79335a87cadf1cbef063bdd2c5c to your computer and use it in GitHub Desktop.

Select an option

Save victorb/dca8a79335a87cadf1cbef063bdd2c5c to your computer and use it in GitHub Desktop.

Revisions

  1. victorb created this gist Nov 3, 2020.
    23 changes: 23 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #! /usr/bin/env bb
    (import '[java.io ByteArrayOutputStream
    ByteArrayInputStream
    PushbackInputStream])
    (require '[clojure.pprint :refer [pprint]])
    (require '[bencode.core :refer [write-bencode
    read-bencode]])

    (defn read-bc [s]
    (-> (.getBytes s "UTF-8")
    ByteArrayInputStream.
    PushbackInputStream.
    read-bencode))

    (defn write-bc [c]
    (-> (doto (ByteArrayOutputStream.)
    (write-bencode c))
    .toString))

    (pprint (read-bc "d2:id7:unknown11:new-session36:7935c405-6ef9-4883-8432-69ce095585777:session4:none6:statusl4:doneee"))

    (pprint
    (write-bc {:op :clone}))