mirror of https://github.com/aria2/aria2
Read aria2.conf using BufferedFile
Read aria2.conf using BufferedFile. Added BufferedFile::transfer().pull/1/head
parent
b3b67f440b
commit
4220c2aadc
|
@ -35,6 +35,7 @@
|
|||
#include "BufferedFile.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <ostream>
|
||||
|
||||
#include "a2io.h"
|
||||
#include "util.h"
|
||||
|
@ -102,4 +103,19 @@ bool BufferedFile::eof()
|
|||
return open_ && feof(fp_);
|
||||
}
|
||||
|
||||
size_t BufferedFile::transfer(std::ostream& out)
|
||||
{
|
||||
size_t count = 0;
|
||||
char buf[4096];
|
||||
while(1) {
|
||||
size_t r = this->read(buf, sizeof(buf));
|
||||
out.write(buf, r);
|
||||
count += r;
|
||||
if(r < sizeof(buf)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -65,6 +66,9 @@ public:
|
|||
int close();
|
||||
// Return true if open_ && feof(fp_) != 0. Otherwise returns false.
|
||||
bool eof();
|
||||
// Convenient method. Read data to end of file and write them into
|
||||
// given stream. Returns written size.
|
||||
size_t transfer(std::ostream& out);
|
||||
// Mode for reading
|
||||
static const std::string READ;
|
||||
// Mode for writing
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
|
@ -56,6 +55,7 @@
|
|||
#include "error_code.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
#include "bittorrent_helper.h"
|
||||
#include "BufferedFile.h"
|
||||
#ifndef HAVE_DAEMON
|
||||
#include "daemon.h"
|
||||
#endif // !HAVE_DAEMON
|
||||
|
@ -133,9 +133,15 @@ void option_processing(Option& op, std::vector<std::string>& uris,
|
|||
ucfname;
|
||||
|
||||
if(File(cfname).isFile()) {
|
||||
std::ifstream cfstream(cfname.c_str(), std::ios::binary);
|
||||
std::stringstream ss;
|
||||
{
|
||||
BufferedFile fp(cfname, BufferedFile::READ);
|
||||
if(fp) {
|
||||
fp.transfer(ss);
|
||||
}
|
||||
}
|
||||
try {
|
||||
oparser.parse(op, cfstream);
|
||||
oparser.parse(op, ss);
|
||||
} catch(OptionHandlerException& e) {
|
||||
std::cerr << "Parse error in " << cfname << "\n"
|
||||
<< e.stackTrace() << std::endl;
|
||||
|
|
Loading…
Reference in New Issue