equal
deleted
inserted
replaced
|
1 // StreamUtils.cpp |
|
2 |
|
3 #include "StdAfx.h" |
|
4 |
|
5 #include "../../Common/MyCom.h" |
|
6 #include "StreamUtils.h" |
|
7 |
|
8 HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize) |
|
9 { |
|
10 if (processedSize != 0) |
|
11 *processedSize = 0; |
|
12 while(size != 0) |
|
13 { |
|
14 UInt32 processedSizeLoc; |
|
15 HRESULT res = stream->Read(data, size, &processedSizeLoc); |
|
16 if (processedSize != 0) |
|
17 *processedSize += processedSizeLoc; |
|
18 data = (Byte *)((Byte *)data + processedSizeLoc); |
|
19 size -= processedSizeLoc; |
|
20 RINOK(res); |
|
21 if (processedSizeLoc == 0) |
|
22 return S_OK; |
|
23 } |
|
24 return S_OK; |
|
25 } |
|
26 |
|
27 HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize) |
|
28 { |
|
29 if (processedSize != 0) |
|
30 *processedSize = 0; |
|
31 while(size != 0) |
|
32 { |
|
33 UInt32 processedSizeLoc; |
|
34 HRESULT res = stream->Write(data, size, &processedSizeLoc); |
|
35 if (processedSize != 0) |
|
36 *processedSize += processedSizeLoc; |
|
37 data = (const void *)((const Byte *)data + processedSizeLoc); |
|
38 size -= processedSizeLoc; |
|
39 RINOK(res); |
|
40 if (processedSizeLoc == 0) |
|
41 return E_FAIL; |
|
42 } |
|
43 return S_OK; |
|
44 } |