summaryrefslogtreecommitdiffstats
path: root/other-licenses/7zstub/src/7zip/Common/StreamUtils.cpp
blob: 712a78585aa0e4f64a4f05577ea37ec9eb6f398c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// StreamUtils.cpp

#include "StdAfx.h"

#include "../../Common/MyCom.h"
#include "StreamUtils.h"

HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
{
  if (processedSize != 0)
    *processedSize = 0;
  while(size != 0)
  {
    UInt32 processedSizeLoc; 
    HRESULT res = stream->Read(data, size, &processedSizeLoc);
    if (processedSize != 0)
      *processedSize += processedSizeLoc;
    data = (Byte *)((Byte *)data + processedSizeLoc);
    size -= processedSizeLoc;
    RINOK(res);
    if (processedSizeLoc == 0)
      return S_OK;
  }
  return S_OK;
}

HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
{
  if (processedSize != 0)
    *processedSize = 0;
  while(size != 0)
  {
    UInt32 processedSizeLoc; 
    HRESULT res = stream->Write(data, size, &processedSizeLoc);
    if (processedSize != 0)
      *processedSize += processedSizeLoc;
    data = (const void *)((const Byte *)data + processedSizeLoc);
    size -= processedSizeLoc;
    RINOK(res);
    if (processedSizeLoc == 0)
      break;
  }
  return S_OK;
}