예제 #1
0
ByteArray ByteArray::fromFile(const std::wstring& fileName, int start, int size)
{
	ByteArray ret;
	
	FILE* input = openFile(fileName,OpenFileMode::ReadBinary);
	if (input == NULL)
		return ret;

	fseek(input,0,SEEK_END);
	int fileSize = ftell(input);

	if (start >= fileSize)
	{
		fclose(input);
		return ret;
	}

	if (size == -1 || start+size > fileSize)
		size = fileSize-start;

	fseek(input,start,SEEK_SET);

	ret.grow(size);
	ret.size_ = size;

	fread(ret.data(),1,size,input);
	fclose(input);

	return ret;
}
예제 #2
0
ByteArray ByteArray::mid(int start, int length)
{
	ByteArray ret;

	if (length < 0)
		length = size_-start;

	if (start >= size_)
		return ret;

	ret.grow(length);
	ret.size_ = length;
	memcpy(ret.data_,&data_[start],length);
	return ret;
}