Last active
July 13, 2021 13:53
-
-
Save zelark/49ffbc0cd701c9299e35421ac2e3d5ab to your computer and use it in GitHub Desktop.
babashka script for viewing torrents files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bb | |
(require '[clojure.java.io :as io]) | |
(require '[bencode.core :refer [read-bencode]]) | |
(require '[clojure.walk :refer [prewalk]]) | |
(require '[clojure.pprint :refer [pprint]]) | |
(import 'java.io.PushbackInputStream) | |
(defn bytes->strings [coll] | |
(prewalk #(if (bytes? %) (String. % "UTF-8") %) coll)) | |
(defn read-torrent [src] | |
(with-open [in (io/input-stream (io/file src))] | |
(-> in PushbackInputStream. read-bencode bytes->strings))) | |
(when-let [src (first *command-line-args*)] | |
(-> (read-torrent src) | |
(assoc-in ["info" "pieces"] "...") ; binary data | |
pprint)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment