pub struct HttpBodyStream { /* private fields */ }Expand description
An owned request body stream, confined to the ArkWeb I/O thread.
Reads consume the stream, so only one operation can use it at a time.
Self::read returns ownership with the bytes; Self::read_to_end closes
it on completion. Both initialize lazily, without rewinding subsequent reads.
Callbacks may run inline and must own their captures ('static).
Once submitted, an operation owns the stream and buffer until its callback. If native code never completes it, those resources must remain allocated: ArkWeb provides no cancellation acknowledgement for outstanding writes.
Implementations§
Source§impl HttpBodyStream
impl HttpBodyStream
Sourcepub unsafe fn new(
raw: *mut ArkWeb_HttpBodyStream,
) -> Result<Self, HttpBodyStreamError>
pub unsafe fn new( raw: *mut ArkWeb_HttpBodyStream, ) -> Result<Self, HttpBodyStreamError>
Take exclusive ownership of a native body stream.
§Safety
raw must be null or a live stream returned by
OH_ArkWebResourceRequest_GetHttpBodyStream, with no operations in flight.
The caller must be on the ArkWeb I/O thread. No other owner may use,
destroy, or change callbacks/userData on this stream after this call.
Sourcepub fn initialize<F>(self, callback: F)
pub fn initialize<F>(self, callback: F)
Initialize without reading, returning the stream for metadata queries. Already initialized streams are returned without another native Init. All errors are delivered once through the callback, possibly inline.
pub fn is_chunked(&self) -> Result<bool, HttpBodyStreamError>
pub fn is_eof(&self) -> Result<bool, HttpBodyStreamError>
pub fn is_in_memory(&self) -> Result<bool, HttpBodyStreamError>
Sourcepub fn size(&self) -> Result<Option<u64>, HttpBodyStreamError>
pub fn size(&self) -> Result<Option<u64>, HttpBodyStreamError>
Total body size after initialization: None for unknown-length chunked
bodies, Some(0) for known empty bodies. Before initialization, errors.
Sourcepub fn read<F>(self, size: usize, callback: F)
pub fn read<F>(self, size: usize, callback: F)
Read at most size bytes, returning the stream at its new position.
A zero-sized read initializes but never calls native Read.
On error the stream is closed. The callback is the sole result channel.
Ownership prevents overlapping reads at compile time:
fn overlap(stream: HttpBodyStream) {
stream.read(1, |_| {});
stream.read(1, |_| {}); // stream has moved into the first operation
}Sourcepub fn read_to_end<F>(self, callback: F)
pub fn read_to_end<F>(self, callback: F)
Collect the remaining body through EOF and close the stream. Handles short reads and unknown lengths; errors also close the stream.