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