https://opendal.apache.org/ logo
opendal read
# general
m
I am seeing a wierd issue with OpenDAL where when I read a lot of bytes into an vec![u8] using read.read(), it only reads some bytes while it fills the rest with 0. Are there some length restriction parameters in the API?
x
Would you like to show the code example?
m
let mut column_chunk_bytes = vec![0u8; (end - start) as usize]; reader.seek(SeekFrom::Start(start as u64)).await.unwrap(); reader.read(&mut column_chunk_bytes).await.unwrap(); let column_chunk_bytes = Bytes::from(column_chunk_bytes);
x
The first line will perform the reset to 0 operations.
m
yeah
but the file should be long enough
x
And please the return value of reader.read()
m
good point
x
Keeping calling read until you fill the buffer or reach 0
m
AH
understood
Is there a way to configure how much it read at a time
x
It’s decided by underlaying storage services implementation.
m
can i tune this number for performance though
also it's kind of annoying if I don't know how many bytes it will return...
x
You can create a buffer reader by op.reader_with(path).buffer(size) to control the read size if you don’t want always read most from the storage services.
You can also use op.read_with(path).range(range) if the range is already known.
From the performance side, there is no difference. opendal already returns the most data it read. Requesting more is just looping internally and doing more memcpy
m
thanks!
2 Views