mirror of
https://github.com/libAthena/athena.git
synced 2025-12-11 14:41:48 +00:00
* Nearly done with the documentation
* Changed BinaryReader/Writer to read and write in 512 byte chunks by default
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
BinaryWriter::BinaryWriter(const Uint8* data, Uint64 length)
|
||||
: Stream(data, length)
|
||||
@@ -39,9 +40,26 @@ void BinaryWriter::save(const std::string& filename)
|
||||
|
||||
FILE* out = fopen(m_filename.c_str(), "wb");
|
||||
if (!out)
|
||||
throw FileNotFoundException(m_filename);
|
||||
throw FileNotFoundException(m_filename);
|
||||
|
||||
Uint32 done = 0;
|
||||
Uint32 blocksize = BLOCKSZ;
|
||||
do
|
||||
{
|
||||
if (blocksize > m_length - done)
|
||||
blocksize = m_length - done;
|
||||
|
||||
Int32 ret = fwrite(m_data + done, 1, blocksize, out);
|
||||
|
||||
if (ret < 0)
|
||||
throw IOException("Error writing data to disk");
|
||||
else if (ret == 0)
|
||||
break;
|
||||
|
||||
done += blocksize;
|
||||
std::cout << "Wrote " << done << " bytes" << std::endl;
|
||||
}while (done < m_length);
|
||||
|
||||
fwrite(m_data, 1, m_length, out);
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user