本文整理汇总了C++中COutFileStream类的典型用法代码示例。如果您正苦于以下问题:C++ COutFileStream类的具体用法?C++ COutFileStream怎么用?C++ COutFileStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了COutFileStream类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: RINOK
HRESULT CAgent::CommonUpdate(
const wchar_t *newArchiveName,
int numUpdateItems,
IArchiveUpdateCallback *updateCallback)
{
if (!CanUpdate())
return E_NOTIMPL;
CMyComPtr<IOutArchive> outArchive;
RINOK(GetArchive()->QueryInterface(IID_IOutArchive, (void **)&outArchive));
COutFileStream *outStreamSpec = new COutFileStream;
CMyComPtr<IOutStream> outStream(outStreamSpec);
UString archiveName = newArchiveName;
{
UString resultPath;
int pos;
if(!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
throw 141716;
NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
}
/*
bool isOK = false;
for (int i = 0; i < (1 << 16); i++)
{
resultName = newArchiveName;
if (i > 0)
{
wchar_t s[32];
ConvertUInt64ToString(i, s);
resultName += s;
}
if (outStreamSpec->Open(realPath))
{
isOK = true;
break;
}
if (::GetLastError() != ERROR_FILE_EXISTS)
return ::GetLastError();
}
if (!isOK)
return ::GetLastError();
*/
if (!outStreamSpec->Create(archiveName, true))
{
// ShowLastErrorMessage();
return E_FAIL;
}
RINOK(outArchive->UpdateItems(outStream, numUpdateItems, updateCallback));
return outStreamSpec->Close();
}
示例3: open_outstream
int open_outstream(const string outfile,
CMyComPtr<ISequentialOutStream> &outStream)
{
COutFileStream *outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
bool open_by_force = (program_mode == PM_TEST) | force;
if (!outStreamSpec->Create(outfile.c_str(), open_by_force))
throw Exception("Cannot open output file " + outfile);
return outStreamSpec->File.GetHandle();
}
示例4: ConvertUInt32ToString
STDMETHODIMP P7ZipArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)
{
wchar_t temp[16];
ConvertUInt32ToString(index + 1, temp);
UString res = temp;
while (res.Length() < 2)
res = UString(L'0') + res;
UString fileName = VolName;
fileName += L'.';
fileName += res;
fileName += VolExt;
COutFileStream *streamSpec = new COutFileStream;
CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);
if (!streamSpec->Create(fileName, false))
return ::GetLastError();
*volumeStream = streamLoc.Detach();
return S_OK;
}
示例5: ConvertUInt32ToString
STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)
{
COM_TRY_BEGIN
char temp[16];
ConvertUInt32ToString(index + 1, temp);
FString res (temp);
while (res.Len() < 2)
res.InsertAtFront(FTEXT('0'));
FString fileName = VolName;
fileName += '.';
fileName += res;
fileName += VolExt;
COutFileStream *streamSpec = new COutFileStream;
CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);
if (!streamSpec->Create(fileName, false))
return ::GetLastError();
*volumeStream = streamLoc.Detach();
return S_OK;
COM_TRY_END
}
示例6: main2
//.........这里部分代码省略.........
if (command.CompareNoCase(L"e") == 0)
encodeMode = true;
else if (command.CompareNoCase(L"d") == 0)
encodeMode = false;
else
IncorrectCommand();
bool stdInMode = parser[NKey::kStdIn].ThereIs;
bool stdOutMode = parser[NKey::kStdOut].ThereIs;
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = 0;
if (stdInMode)
{
inStream = new CStdInFileStream;
MY_SET_BINARY_MODE(stdin);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(GetSystemString(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
return 1;
}
}
CMyComPtr<ISequentialOutStream> outStream;
COutFileStream *outStreamSpec = NULL;
if (stdOutMode)
{
outStream = new CStdOutFileStream;
MY_SET_BINARY_MODE(stdout);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &outputName = nonSwitchStrings[paramIndex++];
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)
示例7: LZMAEncodeFile
bool LZMAEncodeFile ( const char *fromFile, const char *toFile, CProgressInfo7Zip *progress )
{
bool eos = false;
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::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
CMyComPtr<ICompressCoder> encoder = encoderSpec;
UInt32 dictionary = 1 << 21;
UInt32 posStateBits = 2;
UInt32 litContextBits = 3; // for normal files
// UInt32 litContextBits = 0; // for 32-bit data
UInt32 litPosBits = 0;
// UInt32 litPosBits = 2; // for 32-bit data
UInt32 algorithm = 2;
UInt32 numFastBytes = 128;
UInt32 matchFinderCycles = 16 + numFastBytes / 2;
bool matchFinderCyclesDefined = false;
//bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
PROPID propIDs[] =
{
NCoderPropID::kDictionarySize,
NCoderPropID::kPosStateBits,
NCoderPropID::kLitContextBits,
NCoderPropID::kLitPosBits,
NCoderPropID::kAlgorithm,
NCoderPropID::kNumFastBytes,
NCoderPropID::kMatchFinder,
NCoderPropID::kEndMarker,
NCoderPropID::kMatchFinderCycles
};
const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
UString mf = L"BT4";
PROPVARIANT properties[kNumPropsMax];
for (int p = 0; p < 6; p++)
properties[p].vt = VT_UI4;
properties[0].ulVal = UInt32(dictionary);
properties[1].ulVal = UInt32(posStateBits);
properties[2].ulVal = UInt32(litContextBits);
properties[3].ulVal = UInt32(litPosBits);
properties[4].ulVal = UInt32(algorithm);
properties[5].ulVal = UInt32(numFastBytes);
properties[8].vt = VT_UI4;
properties[8].ulVal = UInt32(matchFinderCycles);
properties[6].vt = VT_BSTR;
properties[6].bstrVal = (BSTR)(const wchar_t *)mf;
properties[7].vt = VT_BOOL;
properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
int numProps = kNumPropsMax;
if (!matchFinderCyclesDefined)
numProps--;
if ( encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK )
return false;
encoderSpec->WriteCoderProperties(outStream);
UInt64 fileSize = 0;
if ( eos )
fileSize = (UInt64)(Int64)-1;
else
inStreamSpec->File.GetLength(fileSize);
for (int i = 0; i < 8; i++)
{
Byte b = Byte(fileSize >> (8 * i));
if (outStream->Write(&b, 1, 0) != S_OK)
return false;
}
if ( progress )
{
progress->Init();
progress->SetMax ( fileSize );
progress->ApprovedStart = 1 << 21;
progress->SetIn ( true );
}
HRESULT result = encoder->Code(inStream, outStream, 0, 0, progress );
if (result == E_OUTOFMEMORY)
//.........这里部分代码省略.........
示例8: main2
//.........这里部分代码省略.........
if (command.CompareNoCase(L"e") == 0)
encodeMode = true;
else if (command.CompareNoCase(L"d") == 0)
encodeMode = false;
else
IncorrectCommand();
bool stdInMode = parser[NKey::kStdIn].ThereIs;
bool stdOutMode = parser[NKey::kStdOut].ThereIs;
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = 0;
if (stdInMode)
{
inStream = new CStdInFileStream;
MY_SET_BINARY_MODE(stdin);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(us2fs(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
return 1;
}
}
CMyComPtr<ISequentialOutStream> outStream;
COutFileStream *outStreamSpec = NULL;
if (stdOutMode)
{
outStream = new CStdOutFileStream;
MY_SET_BINARY_MODE(stdout);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &outputName = nonSwitchStrings[paramIndex++];
outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if (!outStreamSpec->Create(us2fs(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";
size_t inSize = (size_t)fileSize;
Byte *inBuffer = 0;
if (inSize != 0)
示例9: main2
//.........这里部分代码省略.........
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = 0;
if (stdInMode)
{
inStream = new CStdInFileStream;
MY_SET_BINARY_MODE(stdin);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(GetSystemString(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
return 1;
}
}
CMyComPtr<ISequentialOutStream> outStream;
if (stdOutMode)
{
outStream = new CStdOutFileStream;
MY_SET_BINARY_MODE(stdout);
}
else
{
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";
示例10: main2
//.........这里部分代码省略.........
CMyComPtr<ISequentialInStream> inStream;
CInFileStream *inStreamSpec = 0;
if (stdInMode)
{
inStream = new CStdInFileStream;
MY_SET_BINARY_MODE(stdin);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &inputName = nonSwitchStrings[paramIndex++];
inStreamSpec = new CInFileStream;
inStream = inStreamSpec;
if (!inStreamSpec->Open(GetSystemString(inputName)))
{
fprintf(stderr, "\nError: can not open input file %s\n",
(const char *)GetOemString(inputName));
return 1;
}
}
CMyComPtr<ISequentialOutStream> outStream;
if (stdOutMode)
{
outStream = new CStdOutFileStream;
MY_SET_BINARY_MODE(stdout);
}
else
{
if (paramIndex >= nonSwitchStrings.Size())
IncorrectCommand();
const UString &outputName = nonSwitchStrings[paramIndex++];
COutFileStream *outStreamSpec = new COutFileStream;
outStream = outStreamSpec;
if (!outStreamSpec->Open(GetSystemString(outputName)))
{
fprintf(stderr, "\nError: can not open output file %s\n",
(const char *)GetOemString(outputName));
return 1;
}
}
UInt64 fileSize;
if (encodeMode)
{
NCompress::NLZMA::CEncoder *encoderSpec =
new NCompress::NLZMA::CEncoder;
CMyComPtr<ICompressCoder> encoder = encoderSpec;
UInt32 dictionary = 1 << 23;
UInt32 posStateBits = 0;
// UInt32 posStateBits = 2;
// UInt32 litContextBits = 3; // for normal files
UInt32 litContextBits = 0; // for 32-bit data
UInt32 litPosBits = 0;
// UInt32 litPosBits = 2; // for 32-bit data
UInt32 algorithm = 2;
UInt32 numFastBytes = 128;
UString mf = L"BT4";
bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
if(parser[NKey::kMode].ThereIs)
if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))
IncorrectCommand();