Skip to content

API Reference

Complete API documentation for Turbo CDN.

Overview

Turbo CDN provides both a CLI tool and a Rust library for intelligent download acceleration.

CLI Commands

turbo-cdn download (alias: dl)

Download a file with intelligent optimization.

bash
turbo-cdn dl <URL> [OUTPUT] [OPTIONS]

Arguments:

  • URL - URL to download (required)
  • OUTPUT - Output path (optional, defaults to current directory)

Options:

OptionDescription
--verbose, -vEnable verbose output
--no-cdnForce direct download (bypass CDN)
--force-cdnForce CDN download
--no-smartDisable smart mode

Examples:

bash
# Smart download (default)
turbo-cdn dl "https://github.com/user/repo/releases/download/v1.0/file.zip"

# Download to specific path
turbo-cdn dl "https://example.com/file.zip" "./downloads/file.zip"

# Verbose output
turbo-cdn dl "https://example.com/file.zip" --verbose

# Direct download (no CDN)
turbo-cdn dl "https://example.com/file.zip" --no-cdn

turbo-cdn optimize (alias: get-optimal-url)

Get the optimized CDN URL without downloading.

bash
turbo-cdn optimize <URL>

Arguments:

  • URL - URL to optimize (required)

Examples:

bash
turbo-cdn optimize "https://github.com/user/repo/releases/download/v1.0/file.zip"

turbo-cdn stats

Show performance statistics.

bash
turbo-cdn stats

Global Options

OptionDescription
--help, -hShow help
--version, -VShow version
--verbose, -vEnable verbose output

Library API

Quick Start

rust
use turbo_cdn::*;

#[tokio::main]
async fn main() -> turbo_cdn::Result<()> {
    let downloader = TurboCdn::new().await?;
    let result = downloader.download_from_url("https://example.com/file.zip").await?;
    println!("Downloaded: {}", result.path.display());
    Ok(())
}

Main Types

TypeDescription
TurboCdnMain client for downloads
TurboCdnBuilderBuilder for configuring client
DownloadOptionsOptions for individual downloads
DownloadResultResult of a download operation
RegionGeographic region enum

Modules

ModuleDescription
turbo_cdnMain module with TurboCdn client
turbo_cdn::async_apiAsync convenience functions
turbo_cdn::async_api::quickQuick one-off operations

Error Handling

Error Types

rust
use turbo_cdn::{Error, Result};

fn handle_download() -> Result<()> {
    // Result<T> is an alias for std::result::Result<T, turbo_cdn::Error>
    Ok(())
}

Error Variants

ErrorDescription
NetworkErrorNetwork connectivity issues
HttpErrorHTTP request/response errors
IoErrorFile system errors
ParseErrorURL or response parsing errors
TimeoutErrorOperation timed out
ConfigErrorConfiguration errors

Error Handling Example

rust
use turbo_cdn::*;

#[tokio::main]
async fn main() {
    let downloader = TurboCdn::new().await.unwrap();
    
    match downloader.download_from_url("https://example.com/file.zip").await {
        Ok(result) => {
            println!("Success: {}", result.path.display());
        }
        Err(e) => {
            eprintln!("Download failed: {}", e);
            // Handle specific error types
            match e {
                Error::NetworkError(_) => eprintln!("Check your network connection"),
                Error::TimeoutError(_) => eprintln!("Try again or increase timeout"),
                _ => eprintln!("Unexpected error"),
            }
        }
    }
}

Async API

Quick Functions

rust
use turbo_cdn::async_api;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Quick URL optimization
    let url = async_api::quick::optimize_url("https://github.com/...").await?;
    
    // Quick download
    let result = async_api::quick::download_url("https://github.com/...").await?;
    
    Ok(())
}

Feature Flags

FeatureDefaultDescription
rustlsUse rustls for TLS (no OpenSSL needed)
native-tlsUse system TLS
fast-hashUse ahash for faster hashing
high-performanceEnable all optimizations

Using Features

toml
# Default (recommended)
[dependencies]
turbo-cdn = "0.7"

# With native TLS
[dependencies]
turbo-cdn = { version = "0.7", default-features = false, features = ["native-tls"] }

Version Compatibility

Turbo CDNRustMSRVreqwest
0.7.x1.70+1.700.13
0.5.x-0.6.x1.70+1.700.12
0.4.x1.65+1.650.11

See Also

Released under the MIT License.