bool ResourceManager::saveFile(const std::string& fileName, std::iostream& in)
{
    std::streampos oldPos = in.tellg();
    in.seekg(0, std::ios::end);
    std::streampos size = in.tellg();
    in.seekg(0, std::ios::beg);
    std::vector<char> buffer(size);
    in.read(&buffer[0], size);
    bool ret = saveFile(fileName, (const uchar*)&buffer[0], size);
    in.seekg(oldPos, std::ios::beg);
    return ret;
}
Esempio n. 2
0
File: Client.cpp Progetto: Damax/zia
void	Client::setResponseContentLength(Transaction& trans, std::iostream& os)
{
  os.seekg(0, std::ios::end);
  int os_length = os.tellg();
  os_length--;
  os.seekg(0, std::ios::beg);
  trans.getResponse().getHeaders().setValue("CONTENT-LENGTH", inttostr(os_length));
}
std::string StringUtilities::GetAsString(std::iostream& i_stream)
{
	int length;
	char* p_buffer;
	
	// get length of file:
	i_stream.seekg (0, std::iostream::end);
	length = static_cast<int>(i_stream.tellg());
	i_stream.seekg (0, std::iostream::beg);

	// allocate memory:
	p_buffer = new char [length];
	//write file
	int pos = 0;
	while(i_stream.good())
	{
		p_buffer[pos] = i_stream.get();
		++pos;
	}

	std::string out(p_buffer, pos);
	delete[] p_buffer;
	return out;
}