diff --git a/src/bencode2.cc b/src/bencode2.cc index 0e24bfcf..181309a8 100644 --- a/src/bencode2.cc +++ b/src/bencode2.cc @@ -34,12 +34,12 @@ /* copyright --> */ #include "bencode2.h" -#include #include #include "fmt.h" #include "DlAbortEx.h" #include "error_code.h" +#include "BufferedFile.h" namespace aria2 { @@ -220,9 +220,12 @@ SharedHandle decode(const unsigned char* data, size_t length, size_t& SharedHandle 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'.",