pub struct SessionEntry {Show 15 fields
pub gid: u64,
pub uris: Vec<String>,
pub options: HashMap<String, String>,
pub paused: bool,
pub total_length: u64,
pub completed_length: u64,
pub upload_length: u64,
pub download_speed: u64,
pub status: String,
pub error_code: Option<i32>,
pub bitfield: Option<Vec<u8>>,
pub num_pieces: Option<u32>,
pub piece_length: Option<u32>,
pub info_hash_hex: Option<String>,
pub resume_offset: Option<u64>,
}Expand description
Represents a single download task in a session file
This struct contains all information needed to resume a download task, including URIs, options, current progress, and status.
§Fields
gid- Unique global identifier for this download taskuris- List of source URLs (primary URL + mirrors)options- Download configuration options as key-value pairspaused- Whether this download is currently pausedtotal_length- Total size of the download in bytescompleted_length- Number of bytes already downloadedupload_length- Number of bytes uploaded (for seeding)download_speed- Current download speed in bytes/secstatus- Current status: “active”, “waiting”, “paused”, or “error”error_code- Error code if status is “error”bitfield- BitTorrent piece completion bitmap (BT only)num_pieces- Number of pieces in torrent (BT only)piece_length- Size of each piece in bytes (BT only)info_hash_hex- Torrent info hash hex string (BT only)resume_offset- File offset for HTTP/FTP resume support
Fields§
§gid: u64Unique global identifier for this download task
uris: Vec<String>List of source URIs (primary URL + mirrors), tab-separated in serialized form
options: HashMap<String, String>Download configuration options as key-value pairs
paused: boolWhether this download is currently paused
total_length: u64Total size of the download in bytes (0 if unknown)
completed_length: u64Number of bytes already downloaded and verified
upload_length: u64Number of bytes uploaded (relevant for BitTorrent seeding)
download_speed: u64Current download speed in bytes/second
status: StringCurrent status of the download: “active”, “waiting”, “paused”, “error”
error_code: Option<i32>Error code if the download is in error state
bitfield: Option<Vec<u8>>Completed piece bitmap encoded as hex string in file format None for non-BT downloads
num_pieces: Option<u32>Total number of pieces in the torrent None for non-BT downloads
piece_length: Option<u32>Size of each piece in bytes None for non-BT downloads
info_hash_hex: Option<String>Info hash of the torrent (hex string) for matching torrent files None for non-BT downloads
resume_offset: Option<u64>File offset where download should resume (for HTTP/FTP range requests) None if resumption is not applicable
Implementations§
Source§impl SessionEntry
impl SessionEntry
Sourcepub fn new(gid: u64, uris: Vec<String>) -> Self
pub fn new(gid: u64, uris: Vec<String>) -> Self
Creates a new SessionEntry with default values
§Arguments
gid- Unique identifier for this download taskuris- List of source URLs (at least one required)
§Returns
A new SessionEntry instance with sensible defaults:
paused: false- All progress fields: 0
status: “active”- All optional fields: None
§Example
use aria2_core::session::session_entry::SessionEntry;
let entry = SessionEntry::new(1, vec!["http://example.com/file.zip".to_string()]);
assert_eq!(entry.gid, 1);
assert_eq!(entry.uris.len(), 1);
assert!(!entry.paused);
assert_eq!(entry.status, "active");Sourcepub fn with_options(self, options: HashMap<String, String>) -> Self
pub fn with_options(self, options: HashMap<String, String>) -> Self
Sets download options using builder pattern
§Arguments
options- HashMap of option key-value pairs
§Returns
Self for method chaining
§Example
use aria2_core::session::session_entry::SessionEntry;
use std::collections::HashMap;
let mut opts = HashMap::new();
opts.insert("split".to_string(), "4".to_string());
opts.insert("dir".to_string(), "/downloads".to_string());
let entry = SessionEntry::new(1, vec!["http://example.com/f".to_string()])
.with_options(opts);
assert_eq!(entry.options.get("split").unwrap(), "4");Source§impl SessionEntry
impl SessionEntry
Sourcepub fn serialize(&self) -> String
pub fn serialize(&self) -> String
Serializes this entry to the session file format
Produces a multi-line string representation suitable for writing to a session file. The format is compatible with aria2’s session format.
§Returns
String containing the serialized entry (including trailing newline)
§Format
uri1\turi2\turi3
GID=hex_value
[PAUSE=true]
option_key=option_value
TOTAL_LENGTH=...
COMPLETED_LENGTH=...
...§Example
use aria2_core::session::session_entry::SessionEntry;
let entry = SessionEntry::new(0xd270c8a2, vec!["http://example.com/file.zip".to_string()]);
let text = entry.serialize();
assert!(text.contains("http://example.com/file.zip"));
assert!(text.contains("GID=d270c8a2"));Sourcepub fn deserialize_line(text: &str) -> Result<SessionEntry>
pub fn deserialize_line(text: &str) -> Result<SessionEntry>
Deserializes a single line of text into a SessionEntry
Parses a text block containing URI lines and property lines (lines starting with space) into a complete SessionEntry.
§Arguments
text- Multi-line string containing one entry’s data
§Returns
Result containing the deserialized SessionEntry or an error
§Note
This is a lower-level parsing function. For parsing multiple entries
from a full session file, use crate::session::session_serializer::deserialize().
Trait Implementations§
Source§impl Clone for SessionEntry
impl Clone for SessionEntry
Source§fn clone(&self) -> SessionEntry
fn clone(&self) -> SessionEntry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more