コード例 #1
0
ファイル: C_LZMA.cpp プロジェクト: RamiroCruzo/freearc_src
int lzma_compress  ( int dictionarySize,
                     int hashSize,
                     int algorithm,
                     int numFastBytes,
                     int matchFinder,
                     int matchFinderCycles,
                     int posStateBits,
                     int litContextBits,
                     int litPosBits,
                     CALLBACK_FUNC *callback,
                     void *auxdata )
{
  CallbackInStream  inStream  (callback, auxdata);
  CallbackOutStream outStream (callback, auxdata);
  NCompress::NLZMA::CEncoder* encoder = new NCompress::NLZMA::CEncoder;

  bool eos = (1==1);  // use End-Of-Stream marker because we don't know filesize apriori

  if (encoder->SetupProperties (dictionarySize,
                                hashSize,
                                posStateBits,
                                litContextBits,
                                litPosBits,
                                algorithm,
                                numFastBytes,
                                matchFinder,
                                matchFinderCycles,
                                GetCompressionThreads() > 1,
                                eos) != S_OK)
  {
    delete encoder;
    return FREEARC_ERRCODE_INVALID_COMPRESSOR;
  }

  HRESULT result = encoder->Code (&inStream, &outStream, 0, 0, 0);
  delete encoder;
  if (inStream.errcode)
    return inStream.errcode;
  if (outStream.errcode)
    return outStream.errcode;
  if (result == E_OUTOFMEMORY)
  {
    return FREEARC_ERRCODE_NOT_ENOUGH_MEMORY;
  }
  else if (result != S_OK)
  {
    //fprintf(stderr, "\nEncoder error = %X\n", (unsigned int)result);
    return FREEARC_ERRCODE_GENERAL;
  }
  return 0;
}
コード例 #2
0
HRESULT __stdcall LZMA_Encode(void *handle, ISequentialInStream *in_stream, ISequentialOutStream *out_stream,
	ICompressProgressInfo *progress)
{
	try
	{
		NCompress::NLZMA::CEncoder *encoder = reinterpret_cast<NCompress::NLZMA::CEncoder *>(handle);
		HRESULT res;

		res = encoder->WriteCoderProperties(out_stream);
		if (res == S_OK)
		{
			res = encoder->Code(in_stream, out_stream, NULL, NULL, progress);
		}
		return res;
	}
	catch(...)
	{
		return E_FAIL;
	}
}