pub struct BlobReader { /* private fields */ }Expand description
Streaming reader for large binary objects (LOBs).
BlobReader implements AsyncRead to provide a streaming interface for
reading large objects. Data can be read in chunks without allocating
additional buffers for each read operation.
§Example
use mssql_client::blob::BlobReader;
use tokio::io::AsyncReadExt;
let data: Bytes = row.get("binary_column")?;
let mut reader = BlobReader::from_bytes(data);
// Read up to 4KB at a time
let mut buffer = vec![0u8; 4096];
let bytes_read = reader.read(&mut buffer).await?;Implementations§
Source§impl BlobReader
impl BlobReader
Sourcepub fn from_bytes(buffer: Bytes) -> Self
pub fn from_bytes(buffer: Bytes) -> Self
Create a new BlobReader from a Bytes buffer.
This is the primary constructor for creating a blob reader from column data retrieved from a query result.
§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;
let data = Bytes::from_static(b"Hello, World!");
let reader = BlobReader::from_bytes(data);
assert_eq!(reader.len(), Some(13));Sourcepub fn empty() -> Self
pub fn empty() -> Self
Create an empty BlobReader.
Returns a reader with no data that will immediately return EOF.
Sourcepub fn from_slice(data: &[u8]) -> Self
pub fn from_slice(data: &[u8]) -> Self
Create a BlobReader from a byte slice.
This copies the data into an owned Bytes buffer.
Sourcepub fn len(&self) -> Option<u64>
pub fn len(&self) -> Option<u64>
Get the total length of the BLOB in bytes.
Returns Some(length) with the total size of the data.
Returns None only for truly streaming implementations where
the total length is unknown in advance.
§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;
let reader = BlobReader::from_bytes(Bytes::from_static(b"test"));
assert_eq!(reader.len(), Some(4));Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the BLOB is empty.
Returns true if the BLOB contains no data.
§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;
let empty = BlobReader::empty();
assert!(empty.is_empty());
let non_empty = BlobReader::from_bytes(Bytes::from_static(b"data"));
assert!(!non_empty.is_empty());Sourcepub fn bytes_read(&self) -> u64
pub fn bytes_read(&self) -> u64
Get the number of bytes read so far.
This tracks progress through the BLOB and can be used for progress reporting.
§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;
let reader = BlobReader::from_bytes(Bytes::from_static(b"Hello"));
assert_eq!(reader.bytes_read(), 0);Sourcepub fn remaining(&self) -> Option<u64>
pub fn remaining(&self) -> Option<u64>
Get the number of bytes remaining to be read.
Returns Some(remaining) if the total length is known.
Sourcepub fn rewind(&mut self)
pub fn rewind(&mut self)
Reset the reader position to the beginning.
After calling this, bytes_read() will return 0 and subsequent
reads will start from the beginning of the data.
Sourcepub fn into_bytes(self) -> Bytes
pub fn into_bytes(self) -> Bytes
Consume the reader and return the underlying Bytes buffer.
This returns the complete data, including any bytes already read. The buffer is not consumed by reads; it remains complete.
§Example
use bytes::Bytes;
use mssql_client::blob::BlobReader;
let data = Bytes::from_static(b"Hello");
let reader = BlobReader::from_bytes(data.clone());
let recovered = reader.into_bytes();
assert_eq!(recovered, data);Sourcepub fn as_bytes(&self) -> &Bytes
pub fn as_bytes(&self) -> &Bytes
Get a reference to the underlying bytes.
Returns the complete buffer, not just unread bytes.
Sourcepub fn unread_slice(&self) -> &[u8] ⓘ
pub fn unread_slice(&self) -> &[u8] ⓘ
Get the unread portion as a slice.
Returns a slice of the data that hasn’t been read yet.
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Check if all data has been read.
Returns true if bytes_read() == len().
Trait Implementations§
Source§impl AsyncRead for BlobReader
impl AsyncRead for BlobReader
Source§impl Clone for BlobReader
impl Clone for BlobReader
Source§impl Debug for BlobReader
impl Debug for BlobReader
Source§impl Default for BlobReader
impl Default for BlobReader
Source§impl From<&[u8]> for BlobReader
impl From<&[u8]> for BlobReader
Source§impl From<&str> for BlobReader
impl From<&str> for BlobReader
Source§impl From<Bytes> for BlobReader
impl From<Bytes> for BlobReader
Source§impl From<String> for BlobReader
impl From<String> for BlobReader
Auto Trait Implementations§
impl !Freeze for BlobReader
impl RefUnwindSafe for BlobReader
impl Send for BlobReader
impl Sync for BlobReader
impl Unpin for BlobReader
impl UnwindSafe for BlobReader
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
Source§fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
fn read_buf<'a, B>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>
Source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
buf. Read moreSource§fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
fn read_u8(&mut self) -> ReadU8<&mut Self>where
Self: Unpin,
Source§fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
fn read_i8(&mut self) -> ReadI8<&mut Self>where
Self: Unpin,
Source§fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
fn read_u16(&mut self) -> ReadU16<&mut Self>where
Self: Unpin,
Source§fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
fn read_i16(&mut self) -> ReadI16<&mut Self>where
Self: Unpin,
Source§fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
fn read_u32(&mut self) -> ReadU32<&mut Self>where
Self: Unpin,
Source§fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
fn read_i32(&mut self) -> ReadI32<&mut Self>where
Self: Unpin,
Source§fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
fn read_u64(&mut self) -> ReadU64<&mut Self>where
Self: Unpin,
Source§fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
fn read_i64(&mut self) -> ReadI64<&mut Self>where
Self: Unpin,
Source§fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
fn read_u128(&mut self) -> ReadU128<&mut Self>where
Self: Unpin,
Source§fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
fn read_i128(&mut self) -> ReadI128<&mut Self>where
Self: Unpin,
Source§fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
fn read_f32(&mut self) -> ReadF32<&mut Self>where
Self: Unpin,
Source§fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
fn read_f64(&mut self) -> ReadF64<&mut Self>where
Self: Unpin,
Source§fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
fn read_u16_le(&mut self) -> ReadU16Le<&mut Self>where
Self: Unpin,
Source§fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
fn read_i16_le(&mut self) -> ReadI16Le<&mut Self>where
Self: Unpin,
Source§fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
fn read_u32_le(&mut self) -> ReadU32Le<&mut Self>where
Self: Unpin,
Source§fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
fn read_i32_le(&mut self) -> ReadI32Le<&mut Self>where
Self: Unpin,
Source§fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
fn read_u64_le(&mut self) -> ReadU64Le<&mut Self>where
Self: Unpin,
Source§fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
fn read_i64_le(&mut self) -> ReadI64Le<&mut Self>where
Self: Unpin,
Source§fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>where
Self: Unpin,
Source§fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>where
Self: Unpin,
Source§fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
fn read_f32_le(&mut self) -> ReadF32Le<&mut Self>where
Self: Unpin,
Source§fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
fn read_f64_le(&mut self) -> ReadF64Le<&mut Self>where
Self: Unpin,
Source§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
buf. Read more