Simplified IteratableChecksumValidator

pull/2/head
Tatsuhiro Tsujikawa 2011-10-13 22:07:22 +09:00
parent ba87268d1c
commit dbb08c08ed
2 changed files with 6 additions and 17 deletions

View File

@ -49,30 +49,23 @@
namespace aria2 { namespace aria2 {
#define BUFSIZE (256*1024)
#define ALIGNMENT 512
IteratableChecksumValidator::IteratableChecksumValidator IteratableChecksumValidator::IteratableChecksumValidator
(const SharedHandle<DownloadContext>& dctx, (const SharedHandle<DownloadContext>& dctx,
const PieceStorageHandle& pieceStorage) const PieceStorageHandle& pieceStorage)
: dctx_(dctx), : dctx_(dctx),
pieceStorage_(pieceStorage), pieceStorage_(pieceStorage),
currentOffset_(0), currentOffset_(0)
buffer_(0)
{} {}
IteratableChecksumValidator::~IteratableChecksumValidator() IteratableChecksumValidator::~IteratableChecksumValidator() {}
{
delete [] buffer_;
}
void IteratableChecksumValidator::validateChunk() void IteratableChecksumValidator::validateChunk()
{ {
if(!finished()) { if(!finished()) {
size_t length = pieceStorage_->getDiskAdaptor()->readData(buffer_, unsigned char buf[4096];
BUFSIZE, size_t length = pieceStorage_->getDiskAdaptor()->readData
currentOffset_); (buf, sizeof(buf), currentOffset_);
ctx_->update(buffer_, length); ctx_->update(buf, length);
currentOffset_ += length; currentOffset_ += length;
if(finished()) { if(finished()) {
std::string actualDigest = ctx_->digest(); std::string actualDigest = ctx_->digest();
@ -105,8 +98,6 @@ uint64_t IteratableChecksumValidator::getTotalLength() const
void IteratableChecksumValidator::init() void IteratableChecksumValidator::init()
{ {
delete [] buffer_;
buffer_ = new unsigned char[BUFSIZE];
currentOffset_ = 0; currentOffset_ = 0;
ctx_ = MessageDigest::create(dctx_->getHashType()); ctx_ = MessageDigest::create(dctx_->getHashType());
} }

View File

@ -53,8 +53,6 @@ private:
off_t currentOffset_; off_t currentOffset_;
SharedHandle<MessageDigest> ctx_; SharedHandle<MessageDigest> ctx_;
unsigned char* buffer_;
public: public:
IteratableChecksumValidator(const SharedHandle<DownloadContext>& dctx, IteratableChecksumValidator(const SharedHandle<DownloadContext>& dctx,
const SharedHandle<PieceStorage>& pieceStorage); const SharedHandle<PieceStorage>& pieceStorage);