本文整理汇总了C++中FileStream::OpenReadBinary方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::OpenReadBinary方法的具体用法?C++ FileStream::OpenReadBinary怎么用?C++ FileStream::OpenReadBinary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream::OpenReadBinary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: net_send_file
int DERPEditor::net_send_file(lua_State *L)
{
if (lua_gettop(L) == 1)
{
const char* path = lua_tostring(L, 1);
FileStream s;
if (!s.OpenReadBinary(path))
{
char msg[4096];
//Format(msg, "Could not open file to send (send_file): '%s'", path);
lua_pushstring(L, msg);
lua_error(L);
return 0;
}
unsigned fsize = s.GetSize();
char* data = new char[fsize];
s.Read(data, fsize);
unsigned long hash = Hash(data, fsize);
s.Close();
Packet* packet = LuaApp::GetInstance()->m_net->CreateEmptyPacket("res", 1 /* datacache */);
// hash, filename, datalen, data
packet->PushInt(hash);
const char* filename = PathFileName(path);
packet->PushString(filename, strlen(filename)+1);
packet->PushInt(fsize);
packet->PushString(data, fsize);
Util::Array<Network::Client*>& Clients = LuaApp::GetInstance()->m_net->GetClients();
Util::Array<Network::Client*>::iterator iter = Clients.begin();
while (iter != Clients.end())
{
printf("Sending to client %d.\n", (*iter)->Ident);
(*iter)->SendPacket(packet);
iter++;
}
delete packet;
delete data;
char ret[256];
//Format(ret, "%X_%s", hash, filename);
lua_pushstring(L, ret);
return 1;
}
else
{
lua_pushstring(L, "Invalid arguments passed to send_file function!");
lua_error(L);
}
return 0;
}
示例2: ReadAllData
MemoryData File::ReadAllData(StringRef filePath)
{
FileStream stream;
if (stream.OpenReadBinary(filePath))
{
return stream.ReadToEnd();
}
return MemoryData::Empty;
}
示例3: Copy
bool File::Copy(StringRef srcFilePath, StringRef destFilePath)
{
FileStream srcFile;
FileStream destFile;
byte buffer[1024];
MemoryData data = MemoryData::FromStatic(buffer);
if (srcFile.OpenReadBinary(srcFilePath) && destFile.OpenNewWriteBinary(destFilePath))
{
while (true)
{
size_t readCount = srcFile.ReadDataTo(data);
if (readCount == 0)
{
return true;
}
data.ForceSetSize(readCount);
destFile.WriteData(data);
}
}
return false;
}