pub struct HttpRangeStream {
pub total_size: Option<u64>,
pub current_offset: u64,
pub chunk_size: u64,
pub state: RangeStreamState,
}Expand description
大容量ファイルやメディアストリームを安全に分割受信するためのステートマシン。
一度に全データをヒープに読み込まず、一定サイズ(chunk_size)ごとに
Range: bytes={start}-{end} で逐次受信し、ヒープ枯渇を防止する。
Fields§
§total_size: Option<u64>リソース全体のバイト数(未知の場合は None)
current_offset: u64次に要求するバイトオフセット
chunk_size: u641回の Range リクエストで要求するチャンクサイズ(バイト数)
state: RangeStreamState現在のストリーム状態
Implementations§
Source§impl HttpRangeStream
impl HttpRangeStream
Sourcepub fn with_total_size(total_size: u64, chunk_size: u64) -> Self
pub fn with_total_size(total_size: u64, chunk_size: u64) -> Self
全体サイズが既知の場合のビルダー。
Sourcepub fn next_request_range(&mut self) -> Option<(u64, u64)>
pub fn next_request_range(&mut self) -> Option<(u64, u64)>
次にリクエストすべきバイト範囲 (start, end) (inclusive) を計算し、状態を Fetching に遷移させる。
すでにストリーム終端(EOF)に達している場合は None を返す。
Sourcepub fn build_next_range_header(&mut self) -> Option<String>
pub fn build_next_range_header(&mut self) -> Option<String>
次の HTTP Range リクエスト用ヘッダ文字列を生成する。
Sourcepub fn process_chunk_response<'a>(
&mut self,
resp_raw: &'a [u8],
) -> Result<&'a [u8], &'static str>
pub fn process_chunk_response<'a>( &mut self, resp_raw: &'a [u8], ) -> Result<&'a [u8], &'static str>
サーバーから受信した生の HTTP 応答を検証・処理し、本文スライスを取り出す。
成功すると Ok(&[u8])(本文データ)を返し、current_offset を進める。
Sourcepub fn remaining_bytes(&self) -> Option<u64>
pub fn remaining_bytes(&self) -> Option<u64>
残り受信予定バイト数(total_size が既知の場合)。
Trait Implementations§
Source§impl Clone for HttpRangeStream
impl Clone for HttpRangeStream
Auto Trait Implementations§
impl Freeze for HttpRangeStream
impl RefUnwindSafe for HttpRangeStream
impl Send for HttpRangeStream
impl Sync for HttpRangeStream
impl Unpin for HttpRangeStream
impl UnsafeUnpin for HttpRangeStream
impl UnwindSafe for HttpRangeStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more