1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// IStream.h 2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __ISTREAM_H 4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __ISTREAM_H 5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 6cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#include "../Common/MyTypes.h" 7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../Common/MyUnknown.h" 8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "IDecl.h" 10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x) 12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x) 13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 14baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTREAM_INTERFACE(ISequentialInStream, 0x01) 15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE; 17cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 18baa3858d3f5d128a5c8466b700098109edcad5f2repo sync /* 19cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky The requirement for caller: (processedSize != NULL). 20cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky The callee can allow (processedSize == NULL) for compatibility reasons. 21cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 22cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (size == 0), this function returns S_OK and (*processedSize) is set to 0. 23cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 24cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (size != 0) 25cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 26cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky Partial read is allowed: (*processedSize <= avail_size && *processedSize <= size), 27cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky where (avail_size) is the size of remaining bytes in stream. 28cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky If (avail_size != 0), this function must read at least 1 byte: (*processedSize > 0). 29cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky You must call Read() in loop, if you need to read exact amount of data. 30cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 31cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 32cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky If seek pointer before Read() call was changed to position past the end of stream: 33cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (seek_pointer >= stream_size), this function returns S_OK and (*processedSize) is set to 0. 34cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 35cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky ERROR CASES: 36cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky If the function returns error code, then (*processedSize) is size of 37cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky data written to (data) buffer (it can be data before error or data with errors). 38cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky The recommended way for callee to work with reading errors: 39cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 1) write part of data before error to (data) buffer and return S_OK. 40cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 2) return error code for further calls of Read(). 41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */ 42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 44baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTREAM_INTERFACE(ISequentialOutStream, 0x02) 45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE; 47cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync /* 49cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky The requirement for caller: (processedSize != NULL). 50cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky The callee can allow (processedSize == NULL) for compatibility reasons. 51cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 52cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if (size != 0) 53cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky { 54cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky Partial write is allowed: (*processedSize <= size), 55cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky but this function must write at least 1 byte: (*processedSize > 0). 56cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky You must call Write() in loop, if you need to write exact amount of data. 57cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky } 58cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 59cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky ERROR CASES: 60cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky If the function returns error code, then (*processedSize) is size of 61cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky data written from (data) buffer. 62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync */ 63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 65cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#ifdef __HRESULT_FROM_WIN32 66cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#define HRESULT_WIN32_ERROR_NEGATIVE_SEEK __HRESULT_FROM_WIN32(ERROR_NEGATIVE_SEEK) 67cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#else 68cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#define HRESULT_WIN32_ERROR_NEGATIVE_SEEK HRESULT_FROM_WIN32(ERROR_NEGATIVE_SEEK) 69cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#endif 70cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 71cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky/* Seek() Function 72cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky If you seek before the beginning of the stream, Seek() function returns error code: 73cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky Recommended error code is __HRESULT_FROM_WIN32(ERROR_NEGATIVE_SEEK). 74cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky or STG_E_INVALIDFUNCTION 75cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 76cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky It is allowed to seek past the end of the stream. 77cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 78cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 79cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky if Seek() returns error, then the value of *newPosition is undefined. 80cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky*/ 81cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 82baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03) 83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE; 85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 87baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04) 88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE; 90baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(SetSize)(UInt64 newSize) PURE; 91baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 92baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 93baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTREAM_INTERFACE(IStreamGetSize, 0x06) 94baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 95baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(GetSize)(UInt64 *size) PURE; 96baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 97baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 98baa3858d3f5d128a5c8466b700098109edcad5f2repo syncSTREAM_INTERFACE(IOutStreamFlush, 0x07) 99baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{ 100baa3858d3f5d128a5c8466b700098109edcad5f2repo sync STDMETHOD(Flush)() PURE; 101baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}; 102baa3858d3f5d128a5c8466b700098109edcad5f2repo sync 103cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 104cd66d540cead3f8200b0c73bad9c276d67896c3dDavid SrbeckySTREAM_INTERFACE(IStreamGetProps, 0x08) 105cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky{ 106cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky STDMETHOD(GetProps)(UInt64 *size, FILETIME *cTime, FILETIME *aTime, FILETIME *mTime, UInt32 *attrib) PURE; 107cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky}; 108cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 109cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckystruct CStreamFileProps 110cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky{ 111cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt64 Size; 112cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt64 VolID; 113cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt64 FileID_Low; 114cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt64 FileID_High; 115cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 NumLinks; 116cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky UInt32 Attrib; 117cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky FILETIME CTime; 118cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky FILETIME ATime; 119cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky FILETIME MTime; 120cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky}; 121cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 122cd66d540cead3f8200b0c73bad9c276d67896c3dDavid SrbeckySTREAM_INTERFACE(IStreamGetProps2, 0x09) 123cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky{ 124cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky STDMETHOD(GetProps2)(CStreamFileProps *props) PURE; 125cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky}; 126cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky 127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif 128