From 048a2cf59737f761876e81a77e8d064c45c752d7 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 11 Oct 2007 16:58:24 +0000 Subject: 2007-10-12 Tatsuhiro Tsujikawa Implemented BitTorrent/http/ftp integrated download. I've rewritten lots of files and now some headers have forward class declarations to reduce compile time. The implementation is extremely alpha stage, I recommend to use this for testing purpose only. --- src/SingleFileAllocationIterator.cc | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/SingleFileAllocationIterator.cc (limited to 'src/SingleFileAllocationIterator.cc') diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc new file mode 100644 index 00000000..1384c163 --- /dev/null +++ b/src/SingleFileAllocationIterator.cc @@ -0,0 +1,67 @@ +/* */ +#include "SingleFileAllocationIterator.h" +#include "AbstractSingleDiskAdaptor.h" + +#define BUFSIZE 16*1024 + +SingleFileAllocationIterator::SingleFileAllocationIterator(AbstractSingleDiskAdaptor* diskAdaptor):_diskAdaptor(diskAdaptor), _offset(diskAdaptor->size()) {} + +SingleFileAllocationIterator::~SingleFileAllocationIterator() {} + +void SingleFileAllocationIterator::allocateChunk() +{ + int32_t bufSize = BUFSIZE; + unsigned char buf[BUFSIZE]; + memset(buf, 0, bufSize); + + _diskAdaptor->writeData(buf, bufSize, _offset); + _offset += bufSize; + + if(_diskAdaptor->getTotalLength() < _offset) { + _diskAdaptor->truncate(getTotalLength()); + _offset = getTotalLength(); + } +} + +bool SingleFileAllocationIterator::finished() +{ + return getCurrentLength() >= getTotalLength(); +} + +int64_t SingleFileAllocationIterator::getTotalLength() +{ + return _diskAdaptor->getTotalLength(); +} -- cgit