summaryrefslogtreecommitdiffstats
path: root/other-licenses/7zstub/src/7zip/Common/LimitedStreams.cpp
blob: c210c9560d5c3bd2b1f50a12b5f17b1ff1bb15d8 (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
// LimitedStreams.cpp

#include "StdAfx.h"

#include "LimitedStreams.h"
#include "../../Common/Defs.h"

void CLimitedSequentialInStream::Init(ISequentialInStream *stream, UInt64 streamSize)
{
  _stream = stream;
  _size = streamSize;
}

STDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
{
  UInt32 processedSizeReal;
  UInt32 sizeToRead = UInt32(MyMin(_size, UInt64(size)));
  HRESULT result = _stream->Read(data, sizeToRead, &processedSizeReal);
  _size -= processedSizeReal;
  if(processedSize != NULL)
    *processedSize = processedSizeReal;
  return result;
}