libtorrent
Canonical Import
(local libtorrent (require :libtorrent))Source Files
src/lua_libtorrent.cpp
What It Provides
libtorrent exposes the optional libtorrent-rasterbar binding for creating/loading torrent metadata, running sessions, managing torrent handles, reading alerts, DHT operations, bencoding, resume/session state, and selected libtorrent constants.
API Summary
- Availability:
availableis true when built with libtorrent support; otherwise functions throw andmissing-reasonexplains the disabled build. - Session creation:
Session(opts)andsession([opts])returnSessionHandleobjects.session-params([opts])creates reusable session parameters. - Metadata helpers include
create-torrent(opts),load-torrent-file(path),load-torrent-buffer(buffer),parse-magnet-uri(uri),make-magnet-uri(path), parameter loaders, resume-data readers/writers, session-param readers/writers,bencode(value), andbdecode(buffer). SessionHandlemethods cover add/find/remove torrents, per-torrent limits/priorities/status/info, pause/resume, DHT start/stop/queries/puts/direct requests, settings, session status/state, alerts, stats requests, anddrop/is-closed.AddTorrentParamsHandleandSessionParamsHandleexpose mutation andto-tablehelpers for parameter workflows.- Constants/tables include
torrent-flags,storage-modes,save-state-flags, anddht-announce-flags; version/category helpers expose native library information.
Examples
(local libtorrent (require :libtorrent))
(when libtorrent.available
(local session (libtorrent.session {:listen-interfaces "0.0.0.0:0"}))
(local parsed (libtorrent.parse-magnet-uri "magnet:?xt=urn:btih:0123456789012345678901234567890123456789"))
(print parsed.info-hash)
(session:drop))Errors and Platform Notes
When libtorrent is not compiled in, available is false and API calls raise libtorrent unavailable (install libtorrent-rasterbar-dev and rebuild). Required option errors are explicit, such as missing torrent-path, save-path, info-hash, DHT host/port, or malformed hex strings. Many operations perform network and filesystem I/O and may raise native libtorrent error messages. verify-mutable-item currently raises that it is unavailable in this build.
Related Modules
fsfor preparing torrent source/output paths.httpfor tracker or metadata service integration outside the libtorrent session.
Aliases and Search Terms
Search terms: libtorrent, BitTorrent, torrent, magnet URI, DHT, bencode, resume data, peer-to-peer, rasterbar.
