mirror of https://github.com/aria2/aria2
bencode2::decodeFromFile is now first read torrent metainfo file into
memory before parsing it.pull/1/head
parent
4220c2aadc
commit
e2d682e0c6
|
@ -34,12 +34,12 @@
|
|||
/* copyright --> */
|
||||
#include "bencode2.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "fmt.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "error_code.h"
|
||||
#include "BufferedFile.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -220,9 +220,12 @@ SharedHandle<ValueBase> decode(const unsigned char* data, size_t length, size_t&
|
|||
|
||||
SharedHandle<ValueBase> decodeFromFile(const std::string& filename)
|
||||
{
|
||||
std::ifstream f(filename.c_str(), std::ios::binary);
|
||||
if(f) {
|
||||
return decode(f);
|
||||
BufferedFile fp(filename, BufferedFile::READ);
|
||||
if(fp) {
|
||||
std::stringstream ss;
|
||||
fp.transfer(ss);
|
||||
fp.close();
|
||||
return decode(ss);
|
||||
} else {
|
||||
throw DL_ABORT_EX2
|
||||
(fmt("Bencode decoding failed: Cannot open file '%s'.",
|
||||
|
|
Loading…
Reference in New Issue