Mercurial > vba-linux
comparison src/win32/7zip/7z/CPP/7zip/Common/LimitedStreams.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // LimitedStreams.cpp | |
2 | |
3 #include "StdAfx.h" | |
4 | |
5 #include "LimitedStreams.h" | |
6 #include "../../Common/Defs.h" | |
7 | |
8 STDMETHODIMP CLimitedSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize) | |
9 { | |
10 UInt32 realProcessedSize = 0; | |
11 UInt32 sizeToRead = (UInt32)MyMin((_size - _pos), (UInt64)size); | |
12 HRESULT result = S_OK; | |
13 if (sizeToRead > 0) | |
14 { | |
15 result = _stream->Read(data, sizeToRead, &realProcessedSize); | |
16 _pos += realProcessedSize; | |
17 if (realProcessedSize == 0) | |
18 _wasFinished = true; | |
19 } | |
20 if(processedSize != NULL) | |
21 *processedSize = realProcessedSize; | |
22 return result; | |
23 } | |
24 | |
25 STDMETHODIMP CLimitedSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) | |
26 { | |
27 HRESULT result = S_OK; | |
28 if (processedSize != NULL) | |
29 *processedSize = 0; | |
30 if (size > _size) | |
31 { | |
32 size = (UInt32)_size; | |
33 if (size == 0) | |
34 { | |
35 _overflow = true; | |
36 return E_FAIL; | |
37 } | |
38 } | |
39 if (_stream) | |
40 result = _stream->Write(data, size, &size); | |
41 _size -= size; | |
42 if (processedSize != NULL) | |
43 *processedSize = size; | |
44 return result; | |
45 } |