misc/libphysfs/lzma/CPP/7zip/Common/OffsetStream.cpp
author Wuzzy <Wuzzy2@mail.ru>
Wed, 22 Aug 2018 16:47:09 +0200
branch0.9.24
changeset 13690 09757d5aead3
parent 12213 bb5522e88ab2
permissions -rw-r--r--
Backed out changeset 076b7d23fab8. Well, the commit in question was needed after all ...

// OffsetStream.cpp

#include "StdAfx.h"

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

HRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)
{
  _offset = offset;
  _stream = stream;
  return _stream->Seek(offset, STREAM_SEEK_SET, NULL);
}

STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
{
  return _stream->Write(data, size, processedSize);
}

STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, 
    UInt64 *newPosition)
{
  UInt64 absoluteNewPosition;
  if (seekOrigin == STREAM_SEEK_SET)
    offset += _offset;
  HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
  if (newPosition != NULL)
    *newPosition = absoluteNewPosition - _offset;
  return result;
}

STDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)
{
  return _stream->SetSize(_offset + newSize);
}