diff options
Diffstat (limited to 'src/JSystem/JSupport/JSUMemoryStream.cpp')
| -rw-r--r-- | src/JSystem/JSupport/JSUMemoryStream.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/src/JSystem/JSupport/JSUMemoryStream.cpp b/src/JSystem/JSupport/JSUMemoryStream.cpp index 0b5f1bc062..494c343313 100644 --- a/src/JSystem/JSupport/JSUMemoryStream.cpp +++ b/src/JSystem/JSupport/JSUMemoryStream.cpp @@ -63,4 +63,53 @@ s32 JSUMemoryInputStream::getLength() const { /* 802DC630-802DC638 2D6F70 0008+00 1/0 0/0 0/0 .text getPosition__20JSUMemoryInputStreamCFv */ s32 JSUMemoryInputStream::getPosition() const { return mPosition; -}
\ No newline at end of file +} + +void JSUMemoryOutputStream::setBuffer(void* pBuffer, s32 length) { + mBuffer = pBuffer; + mLength = length; + mPosition = 0; +} + +s32 JSUMemoryOutputStream::writeData(const void* pData, s32 length) { + if (mPosition + length > mLength) { + length = mLength - mPosition; + } + + if (length > 0) { + memcpy((void*)((s32)mBuffer + mPosition), pData, length); + mPosition += length; + } + + return length; +} + +s32 JSUMemoryOutputStream::seekPos(s32 pos, JSUStreamSeekFrom seekFrom) { + s32 oldPos = mPosition; + + switch (seekFrom) { + case JSUStreamSeekFrom_SET: + mPosition = pos; + break; + case JSUStreamSeekFrom_END: + mPosition = mLength - pos; + break; + case JSUStreamSeekFrom_CUR: + mPosition += pos; + break; + } + + if (mPosition < 0) { + mPosition = 0; + } + + if (mPosition > mLength) { + mPosition = mLength; + } + + return mPosition - oldPos; +} + +s32 JSUMemoryOutputStream::getLength() const { + return mLength; +} |
