• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // OffsetStream.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../Common/Defs.h"
6 
7 #include "OffsetStream.h"
8 
Init(IOutStream * stream,UInt64 offset)9 HRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)
10 {
11   _offset = offset;
12   _stream = stream;
13   return _stream->Seek(offset, STREAM_SEEK_SET, NULL);
14 }
15 
Write(const void * data,UInt32 size,UInt32 * processedSize)16 STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
17 {
18   return _stream->Write(data, size, processedSize);
19 }
20 
Seek(Int64 offset,UInt32 seekOrigin,UInt64 * newPosition)21 STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
22 {
23   UInt64 absoluteNewPosition;
24   if (seekOrigin == STREAM_SEEK_SET)
25   {
26     if (offset < 0)
27       return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
28     offset += _offset;
29   }
30   HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
31   if (newPosition)
32     *newPosition = absoluteNewPosition - _offset;
33   return result;
34 }
35 
SetSize(UInt64 newSize)36 STDMETHODIMP COffsetOutStream::SetSize(UInt64 newSize)
37 {
38   return _stream->SetSize(_offset + newSize);
39 }
40