StreamObjects.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // StreamObjects.cpp
  2. #include "StdAfx.h"
  3. #include "StreamObjects.h"
  4. #include "../../Common/Defs.h"
  5. STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize)
  6. {
  7. UInt32 numBytesToRead = (UInt32)(MyMin(_pos + size, _size) - _pos);
  8. memmove(data, _dataPointer + _pos, numBytesToRead);
  9. _pos += numBytesToRead;
  10. if(processedSize != NULL)
  11. *processedSize = numBytesToRead;
  12. return S_OK;
  13. }
  14. void CWriteBuffer::Write(const void *data, size_t size)
  15. {
  16. size_t newCapacity = _size + size;
  17. _buffer.EnsureCapacity(newCapacity);
  18. memmove(_buffer + _size, data, size);
  19. _size += size;
  20. }
  21. STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize)
  22. {
  23. _writeBuffer.Write(data, size);
  24. if(processedSize != NULL)
  25. *processedSize = size;
  26. return S_OK;
  27. }
  28. STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize)
  29. {
  30. UInt32 newSize = size;
  31. if (_pos + size > _size)
  32. newSize = (UInt32)(_size - _pos);
  33. memmove(_buffer + _pos, data, newSize);
  34. if(processedSize != NULL)
  35. *processedSize = newSize;
  36. _pos += newSize;
  37. if (newSize != size)
  38. return E_FAIL;
  39. return S_OK;
  40. }
  41. STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize)
  42. {
  43. UInt32 realProcessedSize;
  44. HRESULT result = _stream->Read(data, size, &realProcessedSize);
  45. _size += realProcessedSize;
  46. if (processedSize != 0)
  47. *processedSize = realProcessedSize;
  48. return result;
  49. }
  50. STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize)
  51. {
  52. UInt32 realProcessedSize;
  53. HRESULT result = _stream->Write(data, size, &realProcessedSize);
  54. _size += realProcessedSize;
  55. if (processedSize != 0)
  56. *processedSize = realProcessedSize;
  57. return result;
  58. }