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 "BufferedFile.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#include "a2io.h"
|
#include "a2io.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -102,4 +103,19 @@ bool BufferedFile::eof()
|
||||||
return open_ && feof(fp_);
|
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
|
} // namespace aria2
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -65,6 +66,9 @@ public:
|
||||||
int close();
|
int close();
|
||||||
// Return true if open_ && feof(fp_) != 0. Otherwise returns false.
|
// Return true if open_ && feof(fp_) != 0. Otherwise returns false.
|
||||||
bool eof();
|
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
|
// Mode for reading
|
||||||
static const std::string READ;
|
static const std::string READ;
|
||||||
// Mode for writing
|
// Mode for writing
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -56,6 +55,7 @@
|
||||||
#include "error_code.h"
|
#include "error_code.h"
|
||||||
#include "SimpleRandomizer.h"
|
#include "SimpleRandomizer.h"
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
|
#include "BufferedFile.h"
|
||||||
#ifndef HAVE_DAEMON
|
#ifndef HAVE_DAEMON
|
||||||
#include "daemon.h"
|
#include "daemon.h"
|
||||||
#endif // !HAVE_DAEMON
|
#endif // !HAVE_DAEMON
|
||||||
|
@ -133,9 +133,15 @@ void option_processing(Option& op, std::vector<std::string>& uris,
|
||||||
ucfname;
|
ucfname;
|
||||||
|
|
||||||
if(File(cfname).isFile()) {
|
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 {
|
try {
|
||||||
oparser.parse(op, cfstream);
|
oparser.parse(op, ss);
|
||||||
} catch(OptionHandlerException& e) {
|
} catch(OptionHandlerException& e) {
|
||||||
std::cerr << "Parse error in " << cfname << "\n"
|
std::cerr << "Parse error in " << cfname << "\n"
|
||||||
<< e.stackTrace() << std::endl;
|
<< e.stackTrace() << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue