* Nearly done with the documentation

* Changed BinaryReader/Writer to read and write in 512 byte chunks by
default
This commit is contained in:
Antidote
2013-01-26 16:13:19 -08:00
parent ad0505a501
commit 506556e1ae
6 changed files with 209 additions and 27 deletions

View File

@@ -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);
}