add two LoadFromInputStream functions
This commit is contained in:
parent
43e8db0b61
commit
2ba8757dec
@ -29,11 +29,14 @@ namespace hgl
|
||||
|
||||
virtual bool Restart()=0; ///<复位访问指针
|
||||
virtual int64 Skip(int64)=0; ///<跳过指定字节不访问
|
||||
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
|
||||
virtual int64 Seek(int64,SeekOrigin=SeekOrigin::Begin)=0; ///<移动访问指针
|
||||
virtual int64 Tell()const=0; ///<返回当前访问位置
|
||||
virtual int64 GetSize()const=0; ///<取得流长度
|
||||
virtual int64 Available()const=0; ///<剩下的可以不受阻塞访问的字节数
|
||||
};//class InputStream
|
||||
|
||||
int64 LoadFromInputStream(void *buf,int64 max_size,InputStream *is); ///<从输入流中加载指定最大长度的数据
|
||||
void *LoadFromInputStream(int64 *size,InputStream *is); ///<从输入流中加载所有的数据到一块内存
|
||||
}//namespace io
|
||||
}//namespace hgl
|
||||
#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})
|
||||
|
||||
SET(BASE_IO_SOURCE
|
||||
IO/InputStream.cpp
|
||||
IO/DataInputStream.cpp
|
||||
IO/DataOutputStream.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