Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)
Web TippsUse custom web fonts in Google Sheets charts(08.09.2026 um 17:05 Uhr)
Web TippsIntroducing the new 1Password App for Google Chat(08.09.2026 um 18:02 Uhr)

🔧 Programmierung 🕛 vor 2 Monaten 3 Min Lesezeit
0

Smart Resume for File Transfers in Rust — Never Start Over

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

All tests run on an 8-year-old MacBook Air. All results from shipping 7 Mac apps as a solo developer. No sponsored opinion.



A 2GB video transfer that fails at 90% and restarts from zero is a terrible experience. HiyokoMTP and HiyokoAutoSync both implement smart resume. Here's how.









The problem



File transfers fail. USB connections drop. Devices sleep. The user unplugs at the wrong moment.



Without resume: start over. With resume: pick up where you left off.









The approach



Track transfer state in SQLite. On failure, record the partial state. On retry, check the record and resume from the last confirmed position.




CODE
CREATE TABLE transfer_state (
id INTEGER PRIMARY KEY,
file_path TEXT NOT NULL,
total_bytes INTEGER NOT NULL,
transferred_bytes INTEGER DEFAULT 0,
file_hash TEXT,
status TEXT DEFAULT 'in_progress',
started_at INTEGER,
updated_at INTEGER
);












Writing with resume support






CODE
pub async fn transfer_with_resume(
source: &Path,
dest: &Path,
db: &Connection,
) -> Result<(), AppError> {
let file_hash = compute_hash(source)?;

// Check for existing partial transfer
let existing = db.query_row(
"SELECT transferred_bytes FROM transfer_state
WHERE file_path = ? AND file_hash = ? AND status = 'in_progress'"
,
params![source.to_str().unwrap(), &file_hash],
|r| r.get::<_, i64>(0),
).ok();

let start_offset = existing.unwrap_or(0) as u64;

// Open source file, seek to offset
let mut reader = File::open(source)?;
reader.seek(SeekFrom::Start(start_offset))?;

// Open dest file for append if resuming
let mut writer = if start_offset > 0 {
OpenOptions::new().append(true).open(dest)?
} else {
File::create(dest)?
};

// Transfer in chunks, updating DB periodically
let mut transferred = start_offset;
let mut buf = vec![0u8; 65536];

loop {
let n = reader.read(&mut buf)?;
if n == 0 { break; }

writer.write_all(&buf[..n])?;
transferred += n as u64;

// Update progress every 1MB
if transferred % (1024 * 1024) == 0 {
db.execute(
"UPDATE transfer_state SET transferred_bytes = ?, updated_at = ? WHERE file_path = ?",
params![transferred as i64, unix_now(), source.to_str().unwrap()],
)?;
}
}

// Mark complete
db.execute(
"UPDATE transfer_state SET status = 'complete' WHERE file_path = ?",
params![source.to_str().unwrap()],
)?;

Ok(())
}












Validating resumed files



After a resume, verify the file hash of the completed transfer:




CODE
if compute_hash(dest)? != expected_hash {
// Hash mismatch — delete and retry from scratch
std::fs::remove_file(dest)?;
return Err(AppError::Transfer("Hash mismatch after resume".into()));
}






A corrupted partial transfer is worse than starting over. Always validate.









The verdict



Smart resume is the difference between a frustrating tool and a reliable one. SQLite tracking + offset-based writes cover the implementation. The complexity is worth it for any app that transfers large files.






TL;DR: Track transfer state in SQLite with transferred_bytes and file_hash. On retry, seek to the last confirmed offset and append. Update progress every 1MB to keep DB writes cheap. Always verify the final hash — a corrupted resume is worse than starting over.






If this was useful, a ❤️ helps more than you'd think — thanks!



Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
3 Quellen
Use custom web fonts in Google Sheets charts
2 Quellen
Introducing the new 1Password App for Google Chat
1 Quelle
Context-aware access controls are available for Gemini Enterprise in the Admin console
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Smart Resume for File Transfers in Rust — Never Start Over

Thematisch verwandte Begriffe: Smart, Resume, File, Transfers · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...