mirror of
https://github.com/libretro/scummvm.git
synced 2025-04-03 15:21:40 +00:00
COMMON: Rewrite writeStream to work with any ReadStream
This let it work with stream without a known size and avoids allocating big buffers when file is big.
This commit is contained in:
parent
0db796bd98
commit
ead4171bbd
@ -27,6 +27,10 @@
|
|||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kTempBufSize = 65536
|
||||||
|
};
|
||||||
|
|
||||||
uint32 WriteStream::writeStream(ReadStream *stream, uint32 dataSize) {
|
uint32 WriteStream::writeStream(ReadStream *stream, uint32 dataSize) {
|
||||||
void *buf = malloc(dataSize);
|
void *buf = malloc(dataSize);
|
||||||
dataSize = stream->read(buf, dataSize);
|
dataSize = stream->read(buf, dataSize);
|
||||||
@ -36,8 +40,21 @@ uint32 WriteStream::writeStream(ReadStream *stream, uint32 dataSize) {
|
|||||||
return dataSize;
|
return dataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 WriteStream::writeStream(SeekableReadStream *stream) {
|
uint32 WriteStream::writeStream(ReadStream *stream) {
|
||||||
return writeStream(stream, stream->size());
|
uint32 ret = 0;
|
||||||
|
|
||||||
|
void *buf = malloc(kTempBufSize);
|
||||||
|
assert(buf);
|
||||||
|
|
||||||
|
uint32 readSize, writeSize;
|
||||||
|
do {
|
||||||
|
readSize = stream->read(buf, kTempBufSize);
|
||||||
|
writeSize = write(buf, readSize);
|
||||||
|
ret += writeSize;
|
||||||
|
} while(readSize == kTempBufSize && writeSize == readSize);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteStream::writeString(const String &str) {
|
void WriteStream::writeString(const String &str) {
|
||||||
|
@ -288,7 +288,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return The number of bytes written into the stream.
|
* @return The number of bytes written into the stream.
|
||||||
*/
|
*/
|
||||||
uint32 writeStream(SeekableReadStream *stream);
|
uint32 writeStream(ReadStream *stream);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write the given string to the stream.
|
* Write the given string to the stream.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user