fix(media): stream large files and honour size settings (#3387)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-11 13:28:24 +02:00
1 parent 6acd7f3d22
commit 45b78a13c2
97 files changed
+2547 -409

No files matched your search

+18
View File
@@ -2,6 +2,7 @@
use axum::body::Body;
use http_body_util::BodyExt;
use memmap2::Mmap;
use std::{io::SeekFrom, path::Path};
use thiserror::Error;
use tokio::{
@@ -43,6 +44,12 @@ impl SpooledBody {
(file, length)
}
pub fn into_mapped(self) -> std::io::Result<MappedSpool> {
let file = self.file.as_ref().expect("SpooledBody already consumed");
let map = unsafe { Mmap::map(file)? };
Ok(MappedSpool { map, _spool: self })
}
pub fn len(&self) -> u64 {
self.length
}
@@ -52,6 +59,17 @@ impl SpooledBody {
}
}
pub struct MappedSpool {
map: Mmap,
_spool: SpooledBody,
}
impl AsRef<[u8]> for MappedSpool {
fn as_ref(&self) -> &[u8] {
&self.map
}
}
impl Drop for SpooledBody {
fn drop(&mut self) {
if self.budget_reservation > 0 {