add two LoadFromInputStream functions
This commit is contained in:
parent
43e8db0b61
commit
2ba8757dec
@ -34,6 +34,9 @@ namespace hgl
|
|||||||
virtual int64 GetSize()const=0; ///<取得流长度
|
virtual int64 GetSize()const=0; ///<取得流长度
|
||||||
virtual int64 Available()const=0; ///<剩下的可以不受阻塞访问的字节数
|
virtual int64 Available()const=0; ///<剩下的可以不受阻塞访问的字节数
|
||||||
};//class InputStream
|
};//class InputStream
|
||||||
|
|
||||||
|
int64 LoadFromInputStream(void *buf,int64 max_size,InputStream *is); ///<从输入流中加载指定最大长度的数据
|
||||||
|
void *LoadFromInputStream(int64 *size,InputStream *is); ///<从输入流中加载所有的数据到一块内存
|
||||||
}//namespace io
|
}//namespace io
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
#endif//HGL_IO_INPUT_STREAM_INCLUDE
|
#endif//HGL_IO_INPUT_STREAM_INCLUDE
|
||||||
|
@ -16,6 +16,7 @@ SOURCE_GROUP("DataType\\Template" FILES ${TYPE_TEMPLATE_HEADER})
|
|||||||
SOURCE_GROUP("DataType" FILES ${BASE_TYPE_SOURCE})
|
SOURCE_GROUP("DataType" FILES ${BASE_TYPE_SOURCE})
|
||||||
|
|
||||||
SET(BASE_IO_SOURCE
|
SET(BASE_IO_SOURCE
|
||||||
|
IO/InputStream.cpp
|
||||||
IO/DataInputStream.cpp
|
IO/DataInputStream.cpp
|
||||||
IO/DataOutputStream.cpp
|
IO/DataOutputStream.cpp
|
||||||
IO/FileAccess.cpp
|
IO/FileAccess.cpp
|
||||||
|
38
src/IO/InputStream.cpp
Normal file
38
src/IO/InputStream.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include<hgl/io/InputStream.h>
|
||||||
|
|
||||||
|
namespace hgl
|
||||||
|
{
|
||||||
|
namespace io
|
||||||
|
{
|
||||||
|
int64 LoadFromInputStream(void *buf,int64 max_size,InputStream *is)
|
||||||
|
{
|
||||||
|
if(!buf||max_size<=0||!is)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int64 total=is->Available();
|
||||||
|
|
||||||
|
if(total>max_size)
|
||||||
|
total=max_size;
|
||||||
|
|
||||||
|
return is->ReadFully(buf,total);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *LoadFromInputStream(int64 *size,InputStream *is)
|
||||||
|
{
|
||||||
|
if(!is)return(nullptr);
|
||||||
|
|
||||||
|
const int64 total=is->Available();
|
||||||
|
|
||||||
|
if(size)
|
||||||
|
*size=total;
|
||||||
|
|
||||||
|
if(total<=0)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
void *result=new char[total];
|
||||||
|
|
||||||
|
*size=is->ReadFully(result,total);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}//namespace io
|
||||||
|
}//namespace hgl
|
Loading…
x
Reference in New Issue
Block a user