Skip to main content

Crate megalib

Crate megalib 

Source
Expand description

§megalib

Rust client library for Mega.nz cloud storage.

§Features

  • Authentication: Login with email/password, support for HTTP proxies, and specific session handling.
    • Full account registration flow (register + verify).
  • Filesystem Operations:
    • List files and folders (support for recursive listing).
    • Create directories (mkdir).
    • Move (mv), rename, and delete (rm) files/folders.
    • Get file attributes (stat) and user quota information.
  • File Transfers:
    • Robust upload and download with automatic resume support.
    • Parallel transfer workers for improved performance.
    • Progress tracking with custom callbacks.
    • Optional preview generation for media uploads.
  • Sharing & Public Access:
    • Export public download links (export).
    • Parse and download files from public MEGA links.
    • Open and browse public folders (open_folder) without login.

Path-based operations (list, stat, mkdir, export, uploads, etc.) rely on the cached node tree, so call SessionHandle::refresh() after login and after remote changes to keep paths accurate.

§Example: Basic Usage

use megalib::SessionHandle;

// Login
let session = SessionHandle::login("user@example.com", "password").await?;

// List files in root (Cloud Drive root is /Root)
let files = session.list("/Root", false).await?;
for file in files {
    println!("{} ({} bytes)", file.name, file.size);
}

// Upload a file with resume support
session.upload_resumable("local_file.txt", "/Root").await?;

// Download a file to local disk
if let Some(node) = session.stat("/Root/remote_file.txt").await? {
    session.download_to_file(&node, "downloaded_file.txt").await?;
}

§Example: Account Registration

Registration is a two-step process:

use megalib::session::{register, verify_registration};

// Step 1: Initiate registration (sends verification email)
let state = register("user@example.com", "SecurePassword123", "John Doe", None).await?;
println!("Check your email! State to save: {}", state.serialize());

// Step 2: After receiving email, complete registration
// let signup_key = "..."; // Extract from email link
// verify_registration(&state, signup_key).await?;

Re-exports§

pub use error::MegaError;
pub use error::Result;
pub use fs::Node;
pub use fs::NodeType;
pub use fs::Quota;
pub use progress::ProgressCallback;
pub use progress::TransferProgress;
pub use public::PublicFile;
pub use public::PublicFolder;
pub use public::download_public_file;
pub use public::get_public_file_info;
pub use public::open_folder;
pub use session::AccountInfo;
pub use session::FolderSessionBlob;
pub use session::RegistrationState;
pub use session::SessionBlob;
pub use session::SessionHandle;
pub use session::register;
pub use session::verify_registration;

Modules§

api
MEGA API client and types.
base64
MEGA-style URL-safe base64 encoding/decoding.
crypto
Cryptographic operations for MEGA protocol.
error
Error types for the megalib library.
fs
Filesystem operations module.
http
HTTP client wrapper for MEGA API requests.
progress
Progress reporting for file transfers.
public
Public link download without authentication.
session
Session management and registration.