Code cleanup
This commit is contained in:
@@ -5,40 +5,37 @@
|
||||
#include <memory>
|
||||
|
||||
namespace callback {
|
||||
StreamCallback::StreamCallback() :
|
||||
m_counter(0) { }
|
||||
StreamCallback::StreamCallback() : m_counter(0) { }
|
||||
|
||||
StreamCallback::StreamCallback(const std::string& songPath) :
|
||||
m_songPath(songPath),
|
||||
m_counter(0),
|
||||
m_bytesRead(0)
|
||||
{
|
||||
// getting file size
|
||||
std::ifstream song(m_songPath.c_str(), std::ios::binary | std::ios::in | std::ios::ate);
|
||||
m_fileSize = song.tellg();
|
||||
std::cout << "file size is " << m_fileSize << " bytes" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
oatpp::data::v_io_size StreamCallback::read(void *buff, oatpp::data::v_io_size count)
|
||||
{
|
||||
if (m_counter >= m_fileSize) {
|
||||
std::cout << "done streaming song" << std::endl;
|
||||
return 0;
|
||||
StreamCallback::StreamCallback(const std::string& songPath) :
|
||||
m_songPath(songPath),
|
||||
m_counter(0),
|
||||
m_bytesRead(0) {
|
||||
// getting file size
|
||||
std::ifstream song(m_songPath.c_str(), std::ios::binary | std::ios::in | std::ios::ate);
|
||||
m_fileSize = song.tellg();
|
||||
std::cout << "file size is " << m_fileSize << " bytes\n";
|
||||
}
|
||||
|
||||
std::fstream song(m_songPath.c_str(), std::ios::binary | std::ios::in);
|
||||
song.seekg(m_counter);
|
||||
|
||||
std::unique_ptr<char[]> data(new char[count]);
|
||||
oatpp::data::v_io_size StreamCallback::read(void *buff, oatpp::data::v_io_size count) {
|
||||
if (m_counter >= m_fileSize) {
|
||||
std::cout << "done streaming song\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
song.read(data.get(), count);
|
||||
std::memcpy(buff, data.get(), count);
|
||||
std::fstream song(m_songPath.c_str(), std::ios::binary | std::ios::in);
|
||||
song.seekg(m_counter);
|
||||
|
||||
m_counter += count;
|
||||
std::unique_ptr<char[]> data(new char[count]);
|
||||
|
||||
song.close();
|
||||
song.read(data.get(), count);
|
||||
std::memcpy(buff, data.get(), count);
|
||||
|
||||
return count;
|
||||
}
|
||||
m_counter += count;
|
||||
|
||||
song.close();
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user