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 --> */
|
/* copyright --> */
|
||||||
#include "bencode2.h"
|
#include "bencode2.h"
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "fmt.h"
|
#include "fmt.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "error_code.h"
|
#include "error_code.h"
|
||||||
|
#include "BufferedFile.h"
|
||||||
|
|
||||||
namespace aria2 {
|
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)
|
SharedHandle<ValueBase> decodeFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::ifstream f(filename.c_str(), std::ios::binary);
|
BufferedFile fp(filename, BufferedFile::READ);
|
||||||
if(f) {
|
if(fp) {
|
||||||
return decode(f);
|
std::stringstream ss;
|
||||||
|
fp.transfer(ss);
|
||||||
|
fp.close();
|
||||||
|
return decode(ss);
|
||||||
} else {
|
} else {
|
||||||
throw DL_ABORT_EX2
|
throw DL_ABORT_EX2
|
||||||
(fmt("Bencode decoding failed: Cannot open file '%s'.",
|
(fmt("Bencode decoding failed: Cannot open file '%s'.",
|
||||||
|
|
Loading…
Reference in New Issue