2006-04-18 17:28:38 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-04-18 17:28:38 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-09-21 15:31:24 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-04-18 17:28:38 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "ByteArrayDiskWriter.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-05-13 14:15:23 +00:00
|
|
|
#include "A2STR.h"
|
2006-04-18 17:28:38 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
ByteArrayDiskWriter::ByteArrayDiskWriter() {}
|
2006-04-18 17:28:38 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
ByteArrayDiskWriter::~ByteArrayDiskWriter() {}
|
2006-04-18 17:28:38 +00:00
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
void ByteArrayDiskWriter::clear()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
buf_.str(A2STR::NIL);
|
2006-04-18 17:28:38 +00:00
|
|
|
}
|
|
|
|
|
2009-05-04 07:50:38 +00:00
|
|
|
void ByteArrayDiskWriter::initAndOpenFile(uint64_t totalLength)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2006-04-18 17:28:38 +00:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2009-05-04 07:50:38 +00:00
|
|
|
void ByteArrayDiskWriter::openFile(uint64_t totalLength) {}
|
2007-01-08 00:13:25 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void ByteArrayDiskWriter::closeFile() {}
|
2006-04-18 17:28:38 +00:00
|
|
|
|
2009-05-04 07:50:38 +00:00
|
|
|
void ByteArrayDiskWriter::openExistingFile(uint64_t totalLength)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2009-05-04 07:50:38 +00:00
|
|
|
openFile();
|
2006-04-18 17:28:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void ByteArrayDiskWriter::writeData(const unsigned char* data, size_t dataLength, off_t position)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2008-11-17 12:07:24 +00:00
|
|
|
uint64_t length = size();
|
|
|
|
if(length < (uint64_t)position) {
|
2010-06-21 13:51:56 +00:00
|
|
|
buf_.seekp(length, std::ios::beg);
|
2008-11-17 12:07:24 +00:00
|
|
|
for(uint64_t i = length; i < (uint64_t)position; ++i) {
|
2010-06-21 13:51:56 +00:00
|
|
|
buf_.put('\0');
|
2007-06-09 10:06:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
buf_.seekp(position, std::ios::beg);
|
2006-04-18 17:28:38 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
buf_.write(reinterpret_cast<const char*>(data), dataLength);
|
2006-04-18 17:28:38 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
ssize_t ByteArrayDiskWriter::readData(unsigned char* data, size_t len, off_t position)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
buf_.seekg(position, std::ios::beg);
|
|
|
|
buf_.read(reinterpret_cast<char*>(data), len);
|
|
|
|
buf_.clear();
|
|
|
|
return buf_.gcount();
|
2006-04-18 17:28:38 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-11-17 12:07:24 +00:00
|
|
|
uint64_t ByteArrayDiskWriter::size()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
buf_.seekg(0, std::ios::end);
|
|
|
|
buf_.clear();
|
|
|
|
return buf_.tellg();
|
2008-11-17 12:07:24 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|