| CARVIEW |
Select Language
HTTP/1.1 200 OK
Connection: keep-alive
Server: nginx/1.24.0 (Ubuntu)
Content-Type: text/html; charset=utf-8
Cache-Control: public, max-age=300
Content-Encoding: gzip
Via: 1.1 varnish, 1.1 varnish
Accept-Ranges: bytes
Age: 0
Date: Sun, 18 Jan 2026 04:11:21 GMT
X-Served-By: cache-dfw-kdfw8210168-DFW, cache-bom-vanm7210073-BOM
X-Cache: MISS, MISS
X-Cache-Hits: 0, 0
X-Timer: S1768709481.849725,VS0,VE295
Vary: Accept, Accept-Encoding
transfer-encoding: chunked
bencoding-lens: Lenses for bencoded data.
bencoding-lens: Lenses for bencoded data.
Downloads
- bencoding-lens-0.1.0.0.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
| Versions [RSS] | 0.1.0.0 |
|---|---|
| Change log | CHANGELOG.md |
| Dependencies | base (>=4.4 && <4.18), bencoding (>=0.4.5.4 && <0.5), bytestring (>=0.10.4.1 && <0.12), lens (>=4 && <5.2) [details] |
| Tested with | ghc ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.2 |
| License | BSD-3-Clause |
| Copyright | (c) 2021-2022, Joseph Morag |
| Author | Joseph Morag |
| Maintainer | Joseph Morag <jm@josephmorag.com> |
| Uploaded | by jmorag at 2022-03-10T20:25:22Z |
| Category | Data |
| Home page | https://github.com/jmorag/bencoding-lens |
| Bug tracker | https://github.com/jmorag/bencoding-lens/issues |
| Source repo | head: git clone https://github.com/jmorag/bencoding-lens |
| Distributions | |
| Downloads | 134 total (2 in the last 30 days) |
| Rating | (no votes yet) [estimated by Bayesian average] |
| Your Rating |
|
| Status | Docs uploaded by user Build status unknown [no reports yet] |
Readme for bencoding-lens-0.1.0.0
[back to package description]bencoding-lens
Law abiding lenses and traversals for bencoding, ported from lens-aeson. Works with arbitrary bencoded data, although most examples in the wild are torrent files.
{-# LANGUAGE OverloadedStrings #-}
import Control.Lens
import Data.BEncode
import Data.BEncode.Lens
import Network.HTTP.Simple -- from http-conduit
import Crypto.Hash -- from cryptonite
main = do
-- Get the ubuntu 20.04 live server torrent file with http-conduit
torrent <- getResponseBody <$> httpBS "https://releases.ubuntu.com/20.04/ubuntu-20.04.4-live-server-amd64.iso.torrent"
-- Print some interesting bits of the torrent file
-- Announce link
print (torrent ^? key "announce")
-- Just (BString "https://torrent.ubuntu.com/announce")
-- Keys of the top level dict
print (fmap fst (torrent ^@.. members))
-- ["announce","announce-list","comment","created by","creation date","info"]
-- Keys of the info dict
print (fmap fst (torrent ^@.. key "info" . members))
-- ["length","name","piece length","pieces"]
-- Piece length
print (torrent ^? key "info" . key "piece length" . _BInteger)
-- Just 262144
-- Compute the info hash (see definition below)
print (torrent ^?! infoHash)
-- b44a0e20fa5b7cecb77156333b4268dfd7c30afb
infoHash :: (AsBValue t) => Fold t (Digest SHA1)
infoHash = key "info" . to (hashlazy . encode)