Closed kaphula closed 1 year ago
This line:
ok.read(&mut data); // 0 bytes every time?
"data" is an empty Vec and you basically pass a empty slice into read, so of course it will always returns 0.
Also, read is not guaranteed to read all data from the file.
You need to use read_to_end instead:
ok.read_to_end(&mut data).unwrap();
Thanks! What do you mean it is not guaranteed to read all data from the file? How can I guarantee that each file's data will be read correctly?
Just use read_to_end as I have shown you, it will guarantee that.
@kaphula I recommend you to read the doc for std::io::Read, it will clear things up for you.
Yes I did. If I understood correctly matching the result of ok.read_to_end
will catch all possible errors if something goes wrong, and if no errors are found and Ok is returned, all data is loaded correctly. Is this correct?
Yes I did. If I understood correctly matching the result of
ok.read_to_end
will catch all possible errors if something goes wrong, and if no errors are found and Ok is returned and all data was loaded correctly. Is this correct?
yes, that's correct.
Thanks for the help!
Not sure if I am using this correctly but I cannot read entries from a tar file into memory because the read call fills my
Vec<u8>
every time with 0 bytes:Is this how you are supposed to use this library? The example
extract_file.rs
usescopy
to copy the bytes but I cannot use that in my case because of a trait error.