Skip to main content

HttpRangeStream

Struct HttpRangeStream 

Source
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: u64

1回の Range リクエストで要求するチャンクサイズ(バイト数)

§state: RangeStreamState

現在のストリーム状態

Implementations§

Source§

impl HttpRangeStream

Source

pub fn new(chunk_size: u64) -> Self

指定されたチャンクサイズ(既定 64KB 以上推奨)で新規ストリームを構築する。

Source

pub fn with_total_size(total_size: u64, chunk_size: u64) -> Self

全体サイズが既知の場合のビルダー。

Source

pub fn next_request_range(&mut self) -> Option<(u64, u64)>

次にリクエストすべきバイト範囲 (start, end) (inclusive) を計算し、状態を Fetching に遷移させる。 すでにストリーム終端(EOF)に達している場合は None を返す。

Source

pub fn build_next_range_header(&mut self) -> Option<String>

次の HTTP Range リクエスト用ヘッダ文字列を生成する。

Source

pub fn process_chunk_response<'a>( &mut self, resp_raw: &'a [u8], ) -> Result<&'a [u8], &'static str>

サーバーから受信した生の HTTP 応答を検証・処理し、本文スライスを取り出す。

成功すると Ok(&[u8])(本文データ)を返し、current_offset を進める。

Source

pub fn seek(&mut self, new_offset: u64) -> Result<(), &'static str>

読み込み位置をシーク(再配置)する。

Source

pub fn is_eof(&self) -> bool

全データを受信し終えたか判定する。

Source

pub fn remaining_bytes(&self) -> Option<u64>

残り受信予定バイト数(total_size が既知の場合)。

Trait Implementations§

Source§

impl Clone for HttpRangeStream

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpRangeStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.