/* */ #include "SingleFileAllocationIterator.h" #include "BinaryStream.h" #include "Util.h" #include "a2io.h" #define BUFSIZE (256*1024) SingleFileAllocationIterator::SingleFileAllocationIterator(BinaryStream* stream, int64_t offset, int64_t totalLength):_stream(stream), _offset(offset), _totalLength(totalLength), _buffer(0) {} SingleFileAllocationIterator::~SingleFileAllocationIterator() { delete [] _buffer; } void SingleFileAllocationIterator::init() { #ifdef HAVE_POSIX_MEMALIGN _buffer = (unsigned char*)Util::allocateAlignedMemory(512, BUFSIZE); #else _buffer = new unsigned char[BUFSIZE]; #endif // HAVE_POSIX_MEMALIGN memset(_buffer, 0, BUFSIZE); } void SingleFileAllocationIterator::allocateChunk() { _stream->writeData(_buffer, BUFSIZE, _offset); _offset += BUFSIZE; if(_totalLength < _offset) { _stream->truncate(_totalLength); _offset = _totalLength; } } bool SingleFileAllocationIterator::finished() { return _offset >= _totalLength; }