diff options
author | Chris Johns <chrisj@rtems.org> | 2012-11-26 11:04:57 +1100 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2012-11-26 11:04:57 +1100 |
commit | 8fdabca48d74b70a5d35ea31bca09261a587b7f3 (patch) | |
tree | cc0b4308d6b305df34ad0c91f9ea874ce7259e5a /rld-compression.cpp | |
parent | 9af1f3cde74c58deeade11469bf095576fa48ad7 (diff) |
Add writing from images as well as streaming operators.
Add the ability to write to the compressed stream directly from
files::images.
Add streaming operator support which is always in a standard byte
format in the output image.
Diffstat (limited to 'rld-compression.cpp')
-rw-r--r-- | rld-compression.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/rld-compression.cpp b/rld-compression.cpp index 3309371..42c11fe 100644 --- a/rld-compression.cpp +++ b/rld-compression.cpp @@ -106,6 +106,47 @@ namespace rld } void + compressor::write (files::image& input, off_t offset, size_t length) + { + input.seek (offset); + + while (length) + { + size_t appending; + + if (length > (size - level)) + appending = size - level; + else + appending = length; + + input.read ((void*) (buffer + level), appending); + + level += appending; + length -= appending; + total += appending; + + if (level >= size) + { + if (compress) + { + int writing = + ::fastlz_compress (buffer, level, io); + + image.write (io, writing); + + total_compressed += writing; + } + else + { + image.write (buffer, length); + } + + level = 0; + } + } + } + + void compressor::flush () { if (level) |