aboutsummaryrefslogtreecommitdiff
path: root/src/base/io/MemoryStream.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2026-03-07 20:42:37 +0800
committerYuqian Yang <crupest@crupest.life>2026-03-07 20:42:37 +0800
commit38756822825e20eca3b9e01b735946175223d692 (patch)
treefc2a495bfc0e082d5ed9a1642278ae6467fe2742 /src/base/io/MemoryStream.cpp
parent924f4b472712d0cfc55b81dcb3eaed3f8a478288 (diff)
downloadcru-38756822825e20eca3b9e01b735946175223d692.tar.gz
cru-38756822825e20eca3b9e01b735946175223d692.tar.bz2
cru-38756822825e20eca3b9e01b735946175223d692.zip
Refactor stream.
Diffstat (limited to 'src/base/io/MemoryStream.cpp')
-rw-r--r--src/base/io/MemoryStream.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/base/io/MemoryStream.cpp b/src/base/io/MemoryStream.cpp
index 4d289197..555526cd 100644
--- a/src/base/io/MemoryStream.cpp
+++ b/src/base/io/MemoryStream.cpp
@@ -20,9 +20,11 @@ MemoryStream::MemoryStream(
}
}
-MemoryStream::~MemoryStream() {}
-
-void MemoryStream::Close() { DoClose(); }
+MemoryStream::~MemoryStream() {
+ if (buffer_ && release_func_) {
+ release_func_(buffer_, size_);
+ }
+}
Index MemoryStream::DoSeek(Index offset, SeekOrigin origin) {
switch (origin) {
@@ -40,6 +42,10 @@ Index MemoryStream::DoSeek(Index offset, SeekOrigin origin) {
}
Index MemoryStream::DoRead(std::byte* buffer, Index offset, Index size) {
+ if (position_ == size_) {
+ return kEOF;
+ }
+
if (position_ + size > size_) {
size = size_ - position_;
}
@@ -64,10 +70,11 @@ Index MemoryStream::DoWrite(const std::byte* buffer, Index offset, Index size) {
}
void MemoryStream::DoClose() {
- CRU_STREAM_BEGIN_CLOSE
- release_func_(buffer_, size_);
+ if (release_func_) {
+ release_func_(buffer_, size_);
+ release_func_ = {};
+ }
buffer_ = nullptr;
- release_func_ = {};
}
} // namespace cru::io