Mercurial > vba-linux
comparison src/win32/7zip/7z/CPP/7zip/Common/StreamObjects.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 // StreamObjects.cpp | |
2 | |
3 #include "StdAfx.h" | |
4 | |
5 #include "StreamObjects.h" | |
6 #include "../../Common/Defs.h" | |
7 | |
8 | |
9 STDMETHODIMP CSequentialInStreamImp::Read(void *data, UInt32 size, UInt32 *processedSize) | |
10 { | |
11 size_t rem = _size - _pos; | |
12 if (size < rem) | |
13 rem = (size_t)size; | |
14 memcpy(data, _dataPointer + _pos, rem); | |
15 _pos += rem; | |
16 if (processedSize != NULL) | |
17 *processedSize = (UInt32)rem; | |
18 return S_OK; | |
19 } | |
20 | |
21 | |
22 void CWriteBuffer::Write(const void *data, size_t size) | |
23 { | |
24 size_t newCapacity = _size + size; | |
25 _buffer.EnsureCapacity(newCapacity); | |
26 memcpy(_buffer + _size, data, size); | |
27 _size += size; | |
28 } | |
29 | |
30 STDMETHODIMP CSequentialOutStreamImp::Write(const void *data, UInt32 size, UInt32 *processedSize) | |
31 { | |
32 _writeBuffer.Write(data, (size_t)size); | |
33 if(processedSize != NULL) | |
34 *processedSize = size; | |
35 return S_OK; | |
36 } | |
37 | |
38 STDMETHODIMP CSequentialOutStreamImp2::Write(const void *data, UInt32 size, UInt32 *processedSize) | |
39 { | |
40 size_t rem = _size - _pos; | |
41 if (size < rem) | |
42 rem = (size_t)size; | |
43 memcpy(_buffer + _pos, data, rem); | |
44 _pos += rem; | |
45 if (processedSize != NULL) | |
46 *processedSize = (UInt32)rem; | |
47 return (rem == size ? S_OK : E_FAIL); | |
48 } | |
49 | |
50 STDMETHODIMP CSequentialInStreamSizeCount::Read(void *data, UInt32 size, UInt32 *processedSize) | |
51 { | |
52 UInt32 realProcessedSize; | |
53 HRESULT result = _stream->Read(data, size, &realProcessedSize); | |
54 _size += realProcessedSize; | |
55 if (processedSize != 0) | |
56 *processedSize = realProcessedSize; | |
57 return result; | |
58 } | |
59 | |
60 STDMETHODIMP CSequentialOutStreamSizeCount::Write(const void *data, UInt32 size, UInt32 *processedSize) | |
61 { | |
62 UInt32 realProcessedSize; | |
63 HRESULT result = _stream->Write(data, size, &realProcessedSize); | |
64 _size += realProcessedSize; | |
65 if (processedSize != 0) | |
66 *processedSize = realProcessedSize; | |
67 return result; | |
68 } |