~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/7zip/Compress/Copy/CopyCoder.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Compress/CopyCoder.cpp
2
 
 
3
 
#include "StdAfx.h"
4
 
 
5
 
extern "C" 
6
 
7
 
#include "../../../../C/Alloc.h"
8
 
}
9
 
 
10
 
#include "CopyCoder.h"
11
 
#include "../../Common/StreamUtils.h"
12
 
 
13
 
namespace NCompress {
14
 
 
15
 
static const UInt32 kBufferSize = 1 << 17;
16
 
 
17
 
CCopyCoder::~CCopyCoder()
18
 
{
19
 
  ::MidFree(_buffer);
20
 
}
21
 
 
22
 
STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
23
 
    ISequentialOutStream *outStream, 
24
 
    const UInt64 * /* inSize */, const UInt64 *outSize,
25
 
    ICompressProgressInfo *progress)
26
 
{
27
 
  if (_buffer == 0)
28
 
  {
29
 
    _buffer = (Byte *)::MidAlloc(kBufferSize);
30
 
    if (_buffer == 0)
31
 
      return E_OUTOFMEMORY;
32
 
  }
33
 
 
34
 
  TotalSize = 0;
35
 
  for (;;)
36
 
  {
37
 
    UInt32 realProcessedSize;
38
 
    UInt32 size = kBufferSize;
39
 
    if (outSize != 0)
40
 
      if (size > *outSize - TotalSize)
41
 
        size = (UInt32)(*outSize - TotalSize);
42
 
    RINOK(inStream->Read(_buffer, size, &realProcessedSize));
43
 
    if (realProcessedSize == 0)
44
 
      break;
45
 
    RINOK(WriteStream(outStream, _buffer, realProcessedSize));
46
 
    TotalSize += realProcessedSize;
47
 
    if (progress != NULL)
48
 
    {
49
 
      RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
50
 
    }
51
 
  }
52
 
  return S_OK;
53
 
}
54
 
 
55
 
STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)
56
 
{
57
 
  *value = TotalSize;
58
 
  return S_OK;
59
 
}
60
 
 
61
 
}
62