new PIFile::readAll test

This commit is contained in:
2025-09-04 17:52:31 +03:00
parent ef8b785ac6
commit 91144ad338
3 changed files with 31 additions and 3 deletions

View File

@@ -22,6 +22,7 @@
#include "pidir.h"
#include "piincludes_p.h"
#include "piiostream.h"
#include "piliterals_bytes.h"
#include "pitime_win.h"
#include "pitranslator.h"
#ifdef WINDOWS
@@ -276,6 +277,21 @@ PIByteArray PIFile::readAll(bool forceRead) {
}
PIByteArray PIFile::_readAll() {
if (!isOpened()) return {};
llong prev_pos = pos();
PIByteArray ret, buffer(4_KiB);
seekToBegin();
for (;;) {
size_t readed = fread(buffer.data(), 1, buffer.size(), PRIVATE->fd);
if (readed == 0) break;
ret.append(buffer.data(), readed);
}
seek(prev_pos);
return ret;
}
llong PIFile::size() const {
if (isClosed()) return -1;
llong s, cp = pos();

View File

@@ -227,6 +227,8 @@ public:
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
PIByteArray readAll(bool forceRead = false);
PIByteArray _readAll();
//! \~english Set file path to "path" and reopen file if need
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости