diff options
Diffstat (limited to '')
-rw-r--r-- | src/utility/streamUtils.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utility/streamUtils.cpp b/src/utility/streamUtils.cpp index f1d3b9de..f7ea62f3 100644 --- a/src/utility/streamUtils.cpp +++ b/src/utility/streamUtils.cpp @@ -52,6 +52,35 @@ stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os) } +stream::size_type bufferedStreamCopyRange(inputStream& is, outputStream& os, + const stream::size_type start, const stream::size_type length) +{ + const stream::size_type blockSize = + std::min(is.getBlockSize(), os.getBlockSize()); + + is.skip(start); + + std::vector <stream::value_type> vbuffer(blockSize); + + stream::value_type* buffer = &vbuffer.front(); + stream::size_type total = 0; + + while (!is.eof() && total < length) + { + const stream::size_type remaining = std::min(length - total, blockSize); + const stream::size_type read = is.read(buffer, blockSize); + + if (read != 0) + { + os.write(buffer, read); + total += read; + } + } + + return total; +} + + stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os, const stream::size_type length, progressListener* progress) { |