当前位置: 首页>>代码示例>>C++>>正文


C++ FileStream::OpenReadBinary方法代码示例

本文整理汇总了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;
}
开发者ID:pxf,项目名称:pxf-tech2,代码行数:59,代码来源:AppNetLib.cpp

示例2: ReadAllData

MemoryData File::ReadAllData(StringRef filePath)
{
	FileStream stream;
	if (stream.OpenReadBinary(filePath))
	{
		return stream.ReadToEnd();
	}

	return MemoryData::Empty;
}
开发者ID:fjz13,项目名称:Medusa,代码行数:10,代码来源:File.cpp

示例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;
}
开发者ID:fjz13,项目名称:Medusa,代码行数:23,代码来源:File.cpp


注:本文中的FileStream::OpenReadBinary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。