streams: cache file position within AutoFile

Github-Pull: bitcoin/bitcoin#30884
Rebased-From: e624a9bef1
This commit is contained in:
Pieter Wuille
2024-09-12 10:40:19 -04:00
committed by Ava Chow
parent 1b853fdb0a
commit 8229e98116
8 changed files with 48 additions and 35 deletions

View File

@@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
for (uint8_t j = 0; j < 40; ++j) {
file << j;
}
std::rewind(file.Get());
file.seek(0, SEEK_SET);
// The buffer size (second arg) must be greater than the rewind
// amount (third arg).
@@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_skip)
for (uint8_t j = 0; j < 40; ++j) {
file << j;
}
std::rewind(file.Get());
file.seek(0, SEEK_SET);
// The buffer is 25 bytes, allow rewinding 10 bytes.
BufferedFile bf{file, 25, 10};
@@ -444,7 +444,7 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file_rand)
for (uint8_t i = 0; i < fileSize; ++i) {
file << i;
}
std::rewind(file.Get());
file.seek(0, SEEK_SET);
size_t bufSize = InsecureRandRange(300) + 1;
size_t rewindSize = InsecureRandRange(bufSize);