I am in the process of adding the ability to receive data over the network to code used only to read local files. The network library that I use sends and receives data in the form vector<uint8_t>. I would like to be able to reuse the code that processes the data after reading the file, but this code expects std :: istream, is there a way for istream to read vector data? This is the same data, so I feel that there must be a way, but I could not find or figure out the code to do this.
current code:
std::ifstream stream("data.img", std::ios::in | std::ios::binary | std::ios::ate);
if (!stream.is_open())
{
throw std::invalid_argument("Could not open file.");
}
processData(stream);
network structure:
vector<uint8_t> data = networkMessage.data;
std::istream stream = ?
processData(stream);
stream.close();
Is there a way to do this, or am I barking the wrong tree?
source
share