mirror of https://github.com/aria2/aria2
Simplified IteratableChecksumValidator
parent
ba87268d1c
commit
dbb08c08ed
|
@ -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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue