forked from organicmaps/organicmaps
Added string FileReader::ReadAsText()
This commit is contained in:
parent
8cd0f1dac3
commit
835d6ff079
3 changed files with 24 additions and 0 deletions
|
@ -66,3 +66,18 @@ UNIT_TEST(FileReaderNonExistentFileTest)
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(FileReaderReadAsText)
|
||||
{
|
||||
char const fName[] = "zzzuuuuuummmba";
|
||||
{
|
||||
FileWriter f(fName);
|
||||
f.Write(fName, ARRAY_SIZE(fName) - 1);
|
||||
}
|
||||
{
|
||||
FileReader f(fName);
|
||||
string const text = f.ReadAsText();
|
||||
TEST_EQUAL(text, fName, ());
|
||||
}
|
||||
FileWriter::DeleteFile(fName);
|
||||
}
|
||||
|
|
|
@ -116,3 +116,11 @@ string FileReader::GetName() const
|
|||
{
|
||||
return m_pFileData->GetName();
|
||||
}
|
||||
|
||||
string FileReader::ReadAsText() const
|
||||
{
|
||||
vector<char> buffer(Size());
|
||||
buffer.resize(Size());
|
||||
Read(0, &buffer[0], Size());
|
||||
return string(reinterpret_cast<char const *>(&buffer[0]), buffer.size());
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public:
|
|||
|
||||
bool IsEqual(string const & fName) const;
|
||||
string GetName() const;
|
||||
string ReadAsText() const;
|
||||
|
||||
private:
|
||||
FileReader(shared_ptr<FileReaderData> const & pFileData, uint64_t offset, uint64_t size);
|
||||
|
|
Loading…
Add table
Reference in a new issue