{"id":31381645,"url":"https://github.com/aspriddell/csdl","last_synced_at":"2025-09-28T10:40:01.023Z","repository":{"id":225458895,"uuid":"766047097","full_name":"aspriddell/csdl","owner":"aspriddell","description":"A server-focused libtorrent wrapper for C#","archived":false,"fork":false,"pushed_at":"2025-04-27T20:52:58.000Z","size":390,"stargazers_count":8,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-22T05:25:19.542Z","etag":null,"topics":["csharp","dotnet","libtorrent","torrent"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aspriddell.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-03-02T07:28:42.000Z","updated_at":"2025-04-27T20:53:02.000Z","dependencies_parsed_at":"2024-03-14T09:32:07.232Z","dependency_job_id":"17ed2678-fe68-47f0-a99a-110640c0fd9d","html_url":"https://github.com/aspriddell/csdl","commit_stats":null,"previous_names":["aspriddell/csdl"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/aspriddell/csdl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspriddell%2Fcsdl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspriddell%2Fcsdl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspriddell%2Fcsdl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspriddell%2Fcsdl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aspriddell","download_url":"https://codeload.github.com/aspriddell/csdl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aspriddell%2Fcsdl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277315116,"owners_count":25797567,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-27T02:00:08.978Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","libtorrent","torrent"],"created_at":"2025-09-28T10:39:59.976Z","updated_at":"2025-09-28T10:40:01.018Z","avatar_url":"https://github.com/aspriddell.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# csdl\nProviding libtorrent through a C++ library for use in .NET on Windows, Linux, macOS and Android.\n\n## Usage\n[![Latest Nuget](https://img.shields.io/nuget/v/csdl.Native?label=csdl\u0026logo=nuget)](https://nuget.org/packages/csdl)\n\nAdd `csdl` to the project via [NuGet](https://nuget.org/packages/csdl) and create a single `TorrentClient` instance.\nThis will usually be `static` (or singleton if using a dependency container), and a `TorrentClientConfig` can be passed in the constructor to configure the client.\n\n```csharp\n// create a new TorrentClient instance, optionally passing in the configuration\nvar options = new TorrentClientConfig\n{\n    ForceEncryption = true,\n    MaxConnections = 500\n};\n\nusing var client = new TorrentClient(options);\n\n// bonus: there is also an event handler that can be subscribed to if more information is wanted.\nclient.AlertRaised += (sender, args) =\u003e\n{\n    // args can be checked against all classes in the csdl.Alerts namespace for more properties.\n    Console.WriteLine(args.Message);\n};\n```\n\n.torrent files can be parsed either by passing in a file path or a byte array containing the file contents to the `TorrentInfo` class, and the instance will be populated accordingly.\nSome metadata can be accessed from the `TorrentInfo` instance, such as the name of the torrent and a list of files contained within it.\n\n```csharp\nvar filePath = \"path/to/torrent/file.torrent\";\nvar torrentInfo = new TorrentInfo(filePath);\n\n// get the name and list of files\nConsole.WriteLine($\"Name: {torrentInfo.Name}\");\nConsole.WriteLine(\"Files:\");\n\nforeach (var file in torrentInfo.Files)\n{\n    Console.WriteLine($\"- {file.Path} ({file.Size} bytes)\");\n}\n```\n\nAfter parsing a torrent file, it can be \"attached\" to the client to start downloading the files. Note this method will not start a download, but will prepare the client to download the files when `Start` is called.\nThis method also has an overload allowing a custom save path to be specified. If not, the default save path will be used (`client.DefaultDownloadPath`).\n\n```csharp\n// this will be saved to DefaultDownloadPath.\nvar torrentManager = client.AttachTorrent(torrentInfo);\n\n// the metadata can still be accessed but files have additional properties including their final destination and their download priority, which can be changed.\ntorrentManager.Files[0].Priority = TorrentFilePriority.DoNotDownload;\n\n// after setting priorities, the download can begin (or resume if the torrent was previously started)\ntorrentManager.Start();\n\n// if we want a progress update, we can request one\nvar progress = torrentManager.GetCurrentStatus();\n\nif (progress.State == TorrentState.Finished)\n{\n    torrentManager.Stop();\n\n    // when we want to \"dispose\" the manager, we can detach it from the client\n    client.DetachTorrent(torrentManager);\n}\n```\n\nIf we want to wait for the download to complete, a timer and a `TaskCompletionSource` can be used to await the completion of the download.\n\n```csharp\nvoid PerformDownload(TorrentClient client, TorrentInfo info, string savePath = null)\n{\n    var torrentTransfer = new TaskCompletionSource();\n    var torrentManager = client.AttachTorrent(info, savePath);\n    \n    torrentManager.Start();\n    \n    using (new Timer(PerformProgressCheck, null, TimeSpan.Zero, TimeSpan.FromSeconds(1)))\n    {\n        await torrentTransfer.Task;\n    }\n\n    // at this point, the torrentManager has either finished downloading or seeding, and the poll has been stopped.\n\n    client.DetachTorrent(torrentManager);\n    return;\n\n    // this function polls the progress (makes a call to libtorrent) every second to check if the torrent has finished downloading\n    void PerformProgressCheck(object state)\n    {\n        if (torrentManager.GetCurrentStatus().State is TorrentState.Seeding or TorrentState.Finished)\n        {\n            torrentTransfer.SetResult();\n        }\n    }\n}\n```\n\n### Supported Systems\nThe native libraries, `csdl.Native`, are currently built for Windows, macOS and Linux for both x64 and arm64 architectures.\n\nAndroid support is also provided by an optional package, [csdl.Native.android](https://nuget.org/packages/csdl.Native.android) which can be installed alongside `csdl` to extend platform compatibility to Android 5.0+ devices with `x86_64`, `armeabi-v7a` and `arm64-v8a` ABIs.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faspriddell%2Fcsdl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faspriddell%2Fcsdl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faspriddell%2Fcsdl/lists"}