other-licenses/7zstub/src/7zip/Common/StreamUtils.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 // StreamUtils.cpp
     3 #include "StdAfx.h"
     5 #include "../../Common/MyCom.h"
     6 #include "StreamUtils.h"
     8 HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
     9 {
    10   if (processedSize != 0)
    11     *processedSize = 0;
    12   while(size != 0)
    13   {
    14     UInt32 processedSizeLoc; 
    15     HRESULT res = stream->Read(data, size, &processedSizeLoc);
    16     if (processedSize != 0)
    17       *processedSize += processedSizeLoc;
    18     data = (Byte *)((Byte *)data + processedSizeLoc);
    19     size -= processedSizeLoc;
    20     RINOK(res);
    21     if (processedSizeLoc == 0)
    22       return S_OK;
    23   }
    24   return S_OK;
    25 }
    27 HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
    28 {
    29   if (processedSize != 0)
    30     *processedSize = 0;
    31   while(size != 0)
    32   {
    33     UInt32 processedSizeLoc; 
    34     HRESULT res = stream->Write(data, size, &processedSizeLoc);
    35     if (processedSize != 0)
    36       *processedSize += processedSizeLoc;
    37     data = (const void *)((const Byte *)data + processedSizeLoc);
    38     size -= processedSizeLoc;
    39     RINOK(res);
    40     if (processedSizeLoc == 0)
    41       break;
    42   }
    43   return S_OK;
    44 }

mercurial