GithubHelp home page GithubHelp logo

meteogrid / haskell-libtorrent Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eryx67/haskell-libtorrent

0.0 5.0 0.0 194 KB

Haskell bindings for rasterbar libtorrent bit torrent client library

License: BSD 3-Clause "New" or "Revised" License

Haskell 99.90% C++ 0.10%

haskell-libtorrent's Introduction

Libtorrent

libtorrent bindings for Haskell.

Examples

In examples directory there are translations of original Python examples.

These bindings are mostly one to one translation. Example of saving resume data from official documentation could look as:

saveFastresume :: forall m . (MonadIO m, MonadBaseControl IO m) =>
                  Session -> [TorrentHandle] -> LoggingT m ()
saveFastresume ses ths = do
  sessionPause ses
  saveThs <- filterM isValid ths >>= filterM isToSave
  forM_ saveThs $ flip saveResumeData Nothing
  waitAlerts $ length saveThs
  where
    isToSave th = do
      st <- torrentStatus th Nothing
      hm <- getHasMetadata st
      ns <- needSaveResumeData th
      return $ hm && ns
    waitAlerts 0 = pure ()
    waitAlerts n = do
      let alertHlrs = [AlertHandler saveResume, AlertHandler saveResumeFailed]
      processed <- fmap length $ sessionHandleAlerts ses alertHlrs
      waitAlerts $ 0 `max` n - processed
    saveResume a = do
      th <- getHandle a
      st <- torrentStatus th . Just $ BitFlags [QuerySavePath, QueryName]
      rd <- bencodedData <$> saveResumeDataAlertResumeData a
      sp <- getSavePath st
      tn <- getName st
      let rfn = resumeFileName sp tn
      liftIO $ BS.writeFile rfn rd
      $(logInfo) $ sformat ("resume data saved for " % stext % " to " % stext) tn sp
    saveResumeFailed a = do
      th <- getHandle a
      st <- torrentStatus th . Just $ BitFlags [QuerySavePath, QueryName]
      tn <- getName st
      ec <- saveResumeDataFailedAlertError a
      $(logError) $ sformat ("resume data save failed for " % stext % " reason " % shown) tn ec

Documentation

For usage see examples in examples directory. For documentation see haddock generated documentation.

haskell-libtorrent's People

Contributors

eryx67 avatar

Watchers

James Cloos avatar Alberto Valverde avatar Marcos Sánchez Provencio avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.