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