OffsetStream.cpp 872 B

1234567891011121314151617181920212223242526272829303132333435
  1. // OffsetStream.cpp
  2. #include "StdAfx.h"
  3. #include "Common/Defs.h"
  4. #include "OffsetStream.h"
  5. HRESULT COffsetOutStream::Init(IOutStream *stream, UInt64 offset)
  6. {
  7. _offset = offset;
  8. _stream = stream;
  9. return _stream->Seek(offset, STREAM_SEEK_SET, NULL);
  10. }
  11. STDMETHODIMP COffsetOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
  12. {
  13. return _stream->Write(data, size, processedSize);
  14. }
  15. STDMETHODIMP COffsetOutStream::Seek(Int64 offset, UInt32 seekOrigin,
  16. UInt64 *newPosition)
  17. {
  18. UInt64 absoluteNewPosition;
  19. if (seekOrigin == STREAM_SEEK_SET)
  20. offset += _offset;
  21. HRESULT result = _stream->Seek(offset, seekOrigin, &absoluteNewPosition);
  22. if (newPosition != NULL)
  23. *newPosition = absoluteNewPosition - _offset;
  24. return result;
  25. }
  26. STDMETHODIMP COffsetOutStream::SetSize(Int64 newSize)
  27. {
  28. return _stream->SetSize(_offset + newSize);
  29. }