diff options
author | Vincent Richard <[email protected]> | 2012-04-16 20:32:33 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2012-04-16 20:32:33 +0000 |
commit | 4f33877820edee1b47d1b6f4fc800eaad273adaa (patch) | |
tree | 10d5d339f17f2561ef46993de308c2e7d8a9fd79 /src/utility/streamUtils.cpp | |
parent | Split stream.hpp/.cpp into multiple source files. (diff) | |
download | vmime-4f33877820edee1b47d1b6f4fc800eaad273adaa.tar.gz vmime-4f33877820edee1b47d1b6f4fc800eaad273adaa.zip |
Added ability to parse directly from an input stream (eg. file). This allows very big messages to be parsed without loading the whole message data into memory.
Diffstat (limited to 'src/utility/streamUtils.cpp')
-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) { |