本文整理汇总了C++中CMyComPtr::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ CMyComPtr::Read方法的具体用法?C++ CMyComPtr::Read怎么用?C++ CMyComPtr::Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMyComPtr
的用法示例。
在下文中一共展示了CMyComPtr::Read方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LZMADecodeFile
bool LZMADecodeFile ( const char *fromFile, const char *toFile, CProgressInfo7Zip *progress )
{
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if ( !inStreamSpec->Open ( GetSystemString(fromFile) ) )
return false;
CMyComPtr<ISequentialOutStream> outStream;
COutFileStream *outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if ( !outStreamSpec->Create ( GetSystemString(toFile), true ) )
return false;
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
CMyComPtr<ICompressCoder> decoder = decoderSpec;
const UInt32 kPropertiesSize = 5;
Byte properties[kPropertiesSize];
UInt32 processedSize;
if ( ReadStream (inStream, properties, kPropertiesSize, &processedSize) != S_OK )
return false;
if ( processedSize != kPropertiesSize )
return false;
if ( decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK )
return false;
UInt64 fileSize = 0;
for (int i = 0; i < 8; i++)
{
Byte b;
if ( inStream->Read(&b, 1, &processedSize) != S_OK )
return false;
if ( processedSize != 1 )
return false;
fileSize |= ((UInt64)b) << (8 * i);
}
if ( progress )
{
progress->Init();
progress->ApprovedStart = 1 << 21;
progress->SetMax ( fileSize );
}
if ( decoder->Code(inStream, outStream, 0, &fileSize, progress) != S_OK )
// decoder error
return false;
return true;
}
示例2: decode
void decode(NCompress::NLzma::CDecoder *decoderSpec,
CMyComPtr<ISequentialInStream> inStream,
CMyComPtr<ISequentialOutStream> outStream)
{
const UInt32 kPropertiesSize = 5;
Byte properties[kPropertiesSize];
UInt32 processedSize;
UInt64 fileSize = 0;
if (inStream->Read(properties, kPropertiesSize, &processedSize) != S_OK)
throw Exception("Read error");
if (processedSize != kPropertiesSize)
throw Exception("Read error");
if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK)
throw Exception("SetDecoderProperties() error");
for (int i = 0; i < 8; i++)
{
Byte b;
if (inStream->Read(&b, sizeof(b), &processedSize) != S_OK)
throw Exception("Read error");
if (processedSize != 1)
throw Exception("Read error");
fileSize |= ((UInt64)b) << (8 * i);
}
if (decoderSpec->Code(inStream, outStream, 0, &fileSize, 0) != S_OK)
throw Exception("Decoder error");
}
示例3:
unsigned char *LZMADecodeData ( unsigned char *fromData, long fromSize, long &toSize, CProgressInfo7Zip *progress )
{
CMyComPtr<ISequentialInStream> inStream;
CInDataStream *inStreamSpec = new CInDataStream;
inStream = inStreamSpec;
inStreamSpec->LoadData ( fromData, fromSize );
NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder;
CMyComPtr<ICompressCoder> decoder = decoderSpec;
const UInt32 kPropertiesSize = 5;
Byte properties[kPropertiesSize];
UInt32 processedSize;
if ( ReadStream (inStream, properties, kPropertiesSize, &processedSize) != S_OK )
return NULL;
if ( processedSize != kPropertiesSize )
return NULL;
if ( decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK )
return NULL;
UInt64 fileSize = 0;
for (int i = 0; i < 8; i++)
{
Byte b;
if ( inStream->Read(&b, 1, &processedSize) != S_OK )
return NULL;
if ( processedSize != 1 )
return NULL;
fileSize |= ((UInt64)b) << (8 * i);
}
CMyComPtr<ISequentialOutStream> outStream;
COutDataStream *outStreamSpec = new COutDataStream;
outStream = outStreamSpec;
outStreamSpec->Create ( fileSize );
// CProgressInfo *progressInfoSpec = new CProgressInfo;
// CMyComPtr<ICompressProgressInfo> progressInfo = progress;
if ( progress )
{
progress->Init();
progress->ApprovedStart = 1 << 21;
progress->SetMax ( fileSize );
}
if ( decoder->Code(inStream, outStream, 0, &fileSize, progress) != S_OK )
// decoder error
return NULL;
toSize = outStreamSpec->GetCurrentSize ();
return outStreamSpec->GetData ();
}
示例4: ReadStream
static bool ReadStream(CMyComPtr<IInStream> & inStream, Int64 offset, UINT32 seekOrigin, CByteBuffer & signature)
{
UInt64 savedPosition = 0;
UInt64 newPosition = 0;
#if MY_VER_MAJOR >= 15
UInt32 readCount = signature.Size();
#else
UInt32 readCount = signature.GetCapacity();
#endif
unsigned char * buf = signature;
if (S_OK != inStream->Seek(0, FILE_CURRENT, &savedPosition))
return false;
if (S_OK != inStream->Seek(offset, seekOrigin, &newPosition)) {
inStream->Seek(savedPosition, FILE_BEGIN, &newPosition); //restore pos
return false;
}
while (readCount > 0) {
UInt32 processedCount = 0;
if (S_OK != inStream->Read(buf, readCount, &processedCount)) {
inStream->Seek(savedPosition, FILE_BEGIN, &newPosition); //restore pos
return false;
}
if (processedCount == 0)
break;
readCount -= processedCount;
buf += processedCount;
}
inStream->Seek(savedPosition, FILE_BEGIN, &newPosition); //restore pos
return readCount == 0;
}
示例5: main2
//.........这里部分代码省略.........
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &outputName = nonSwitchStrings[paramIndex++];
COutFileStream *outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if (!outStreamSpec->Create(GetSystemString(outputName), true))
{
fprintf(stderr, "\nError: can not open output file %s\n",
(const char *)GetOemString(outputName));
return 1;
}
}
if (parser[NKey::kFilter86].ThereIs)
{
// -f86 switch is for x86 filtered mode: BCJ + LZMA.
if (parser[NKey::kEOS].ThereIs || stdInMode)
throw "Can not use stdin in this mode";
UInt64 fileSize;
inStreamSpec->File.GetLength(fileSize);
if (fileSize > 0xF0000000)
throw "File is too big";
UInt32 inSize = (UInt32)fileSize;
Byte *inBuffer = 0;
if (inSize != 0)
{
inBuffer = (Byte *)MyAlloc((size_t)inSize);
if (inBuffer == 0)
throw kCantAllocate;
}
UInt32 processedSize;
if (inStream->Read(inBuffer, (UInt32)inSize, &processedSize) != S_OK)
throw "Can not read";
if ((UInt32)inSize != processedSize)
throw "Read size error";
Byte *outBuffer = 0;
size_t outSizeProcessed;
if (encodeMode)
{
// we allocate 105% of original size for output buffer
size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
if (outSize != 0)
{
outBuffer = (Byte *)MyAlloc((size_t)outSize);
if (outBuffer == 0)
throw kCantAllocate;
}
if (!dictionaryIsDefined)
dictionary = 1 << 23;
int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed,
dictionary, SZ_FILTER_AUTO);
if (res != 0)
{
fprintf(stderr, "\nEncoder error = %d\n", (int)res);
return 1;
}
}
else
{
size_t outSize;
if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)
throw "data error";
if (outSize != 0)