mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
fix(media): stream large files and honour size settings (#3387)
This commit is contained in:
1 parent
6acd7f3d22
commit
45b78a13c2
97 files changed
+2547
-409
No files matched your search
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user