Overview
megalib is an async Rust client library for working with MEGA.nz accounts, files, folders, shares, and public links. It is built as a Rust port of the MEGA C++ SDK and exposes high-level SessionHandle APIs for authenticated account operations plus public-link helpers for unauthenticated downloads and folder browsing.
[!NOTE] This is an unofficial client library and is not affiliated with, endorsed by, or supported by Mega Limited.
Capabilities
- Authentication and accounts: login, proxy login, registration, email verification, password changes, session loading, account info, and quota lookup.
- Cached node tree:
fetch_nodes, root discovery, children by handle, child lookup by name, descendant traversal, contact roots, and inshare/outshare queries. - Filesystem operations: stat, create folder, move, rename, remove, export, and share operations through node-first APIs or explicit path-based compatibility aliases.
- Transfers: file upload/download, resumable upload/download examples, byte and reader uploads, progress callbacks, parallel transfer workers, and HTTP/HTTPS/SOCKS5 proxy support.
- Public access: parse MEGA links, inspect and download public files, export account files, and open public folders without logging in.
- Optional previews: compile with the
previewfeature and callenable_previews(true)to generate upload thumbnails for supported media.
Installation
Add megalib and an async runtime to your Cargo.toml:
[]
= "0.11.0"
= { = "1", = ["full"] }
For upload thumbnail generation:
[]
= { = "0.11.0", = ["preview"] }
= { = "1", = ["full"] }
Quickstart
Log in, populate the cached node tree, and list the Cloud Drive root:
use ;
async
[!TIP] New code should prefer node-first APIs after
fetch_nodes(). Path-based helpers are still available as explicit compatibility aliases such aslist_by_path,stat_by_path,mkdir_by_path,mv_by_path,rename_by_path,rm_by_path,upload_by_path,upload_resumable_by_path,export_by_path, andshare_folder_by_path.
Examples
Each example is a runnable binary under examples/. Use --help to inspect the exact flags for any example:
Common workflows:
# Authentication and browsing
# Upload and download
# Filesystem operations
# Sharing and public links
# Account management
Authenticated examples that define --proxy accept proxy URLs such as http://proxy:8080 or socks5://proxy:1080.
API Notes
SessionHandle::fetch_nodes()populates the cached tree used by node-first APIs and path compatibility aliases.- Cloud Drive paths are rooted at
/Root; public folder paths are rooted at the shared folder name. - Deprecated path-first canonical names remain for compatibility, but new code should use the explicit
*_by_pathaliases or node-first methods. - Public file helpers in
megalib::publiccan inspect and download MEGA links without an authenticated session. - Video thumbnails with the
previewfeature requireffmpegthumbnailerto be installed and available onPATH.