コード例 #1
1
ファイル: File.cpp プロジェクト: donbex/spkutils
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
0
ファイル: File.cpp プロジェクト: donbex/spkutils
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 ();
}
コード例 #3
0
ファイル: LzmaHandler.cpp プロジェクト: OwenTan/AndroidP7zip
HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
    ICompressProgressInfo *progress)
{
  if (header.FilterID > 1)
    return E_NOTIMPL;

  {
    CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
    _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
    if (!setDecoderProperties)
      return E_NOTIMPL;
    RINOK(setDecoderProperties->SetDecoderProperties2(header.LzmaProps, 5));
  }

  CMyComPtr<ICompressSetOutStream> setOutStream;

  bool filteredMode = (header.FilterID == 1);

  if (filteredMode)
  {
    _bcjStream.QueryInterface(IID_ICompressSetOutStream, &setOutStream);
    if (!setOutStream)
      return E_NOTIMPL;
    RINOK(setOutStream->SetOutStream(outStream));
    outStream = _bcjStream;
  }

  const UInt64 *Size = header.HasSize() ? &header.Size : NULL;
  HRESULT res = _lzmaDecoderSpec->CodeResume(outStream, Size, progress);

  if (filteredMode)
  {
    CMyComPtr<IOutStreamFlush> flush;
    _bcjStream.QueryInterface(IID_IOutStreamFlush, &flush);
    if (flush)
    {
      HRESULT res2 = flush->Flush();
      if (res == S_OK)
        res = res2;
    }
    HRESULT res2 = setOutStream->ReleaseOutStream();
    if (res == S_OK)
      res = res2;
  }
  RINOK(res);

  if (header.HasSize())
    if (_lzmaDecoderSpec->GetOutputProcessedSize() != header.Size)
      return S_FALSE;

  return S_OK;
}
コード例 #4
0
ファイル: LzmaHandler.cpp プロジェクト: anchowee/libcodecs
HRESULT CDecoder::Create(
    DECL_EXTERNAL_CODECS_LOC_VARS
    bool filteredMode, ISequentialInStream *inStream)
{
  if (!_lzmaDecoder)
  {
    _lzmaDecoderSpec = new NCompress::NLzma::CDecoder;
    _lzmaDecoder = _lzmaDecoderSpec;
  }

  if (filteredMode)
  {
    if (!_bcjStream)
    {
      CMyComPtr<ICompressCoder> coder;
      RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS k_BCJ, coder, false));
      if (!coder)
        return E_NOTIMPL;
      coder.QueryInterface(IID_ISequentialOutStream, &_bcjStream);
      if (!_bcjStream)
        return E_NOTIMPL;
    }
  }

  return _lzmaDecoderSpec->SetInStream(inStream);
}
コード例 #5
0
ファイル: 7zlzma.cpp プロジェクト: waddlesplash/sneese
bool decompress_lzma_7z(ISequentialInStream& in, unsigned in_size, ISequentialOutStream& out, unsigned out_size) throw ()
{
  try
  {
    NCompress::NLZMA::CDecoder cc;

    UINT64 in_size_l = in_size;
    UINT64 out_size_l = out_size;

    if (cc.ReadCoderProperties(&in) != S_OK)                 { return(false); }
    if (cc.Code(&in, &out, &in_size_l, &out_size_l) != S_OK) { return(false); }
    if (out.size_get() != out_size || out.overflow_get())    { return(false); }

    return(true);
  }
  catch (...)
  {
    return(false);
  }
}
コード例 #6
0
ファイル: C_LZMA.cpp プロジェクト: RamiroCruzo/freearc_src
int lzma_decompress( 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::CDecoder* decoder = new NCompress::NLZMA::CDecoder;

  if (decoder->SetupProperties(dictionarySize, posStateBits, litContextBits, litPosBits) != S_OK)
  {
    delete decoder;
    return 1;
  }

  UInt64 fileSize = (UInt64)-1;

  HRESULT result = decoder->Code(&inStream, &outStream, 0, &fileSize, 0);
  delete decoder;
  if (inStream.errcode)
    return inStream.errcode;
  if (outStream.errcode)
    return outStream.errcode;
  if (result == E_OUTOFMEMORY)
  {
    return FREEARC_ERRCODE_NOT_ENOUGH_MEMORY;
  }
  if (result != S_OK)
  {
    //fprintf(stderr, "\nDecoder error = %X\n", (unsigned int)result);
    return FREEARC_ERRCODE_GENERAL;
  }
  return 0;
}
コード例 #7
0
ファイル: LzmaHandler.cpp プロジェクト: cube-soft/7z
HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
    ICompressProgressInfo *progress)
{
  if (header.FilterID > 1)
    return E_NOTIMPL;

  RINOK(_lzmaDecoderSpec->SetDecoderProperties2(header.LzmaProps, 5));

  bool filteredMode = (header.FilterID == 1);

  if (filteredMode)
  {
    RINOK(_filterCoder->SetOutStream(outStream));
    outStream = _bcjStream;
    RINOK(_filterCoder->SetOutStreamSize(NULL));
  }

  const UInt64 *Size = header.HasSize() ? &header.Size : NULL;
  HRESULT res = _lzmaDecoderSpec->CodeResume(outStream, Size, progress);

  if (filteredMode)
  {
    {
      HRESULT res2 = _filterCoder->OutStreamFinish();
      if (res == S_OK)
        res = res2;
    }
    HRESULT res2 = _filterCoder->ReleaseOutStream();
    if (res == S_OK)
      res = res2;
  }
  
  RINOK(res);

  if (header.HasSize())
    if (_lzmaDecoderSpec->GetOutputProcessedSize() != header.Size)
      return S_FALSE;

  return S_OK;
}
コード例 #8
0
ファイル: LzmaHandler.cpp プロジェクト: cube-soft/7z
HRESULT CDecoder::Create(bool filteredMode, ISequentialInStream *inStream)
{
  if (!_lzmaDecoder)
  {
    _lzmaDecoderSpec = new NCompress::NLzma::CDecoder;
    _lzmaDecoderSpec->FinishStream = true;
    _lzmaDecoder = _lzmaDecoderSpec;
  }

  if (filteredMode)
  {
    if (!_bcjStream)
    {
      _filterCoder = new CFilterCoder(false);
      CMyComPtr<ICompressCoder> coder = _filterCoder;
      _filterCoder->Filter = new NCompress::NBcj::CCoder(false);
      _bcjStream = _filterCoder;
    }
  }

  return _lzmaDecoderSpec->SetInStream(inStream);
}
コード例 #9
0
ファイル: LzmaHandler.cpp プロジェクト: cube-soft/7z
 HRESULT ReadInput(Byte *data, UInt32 size, UInt32 *processedSize)
   { return _lzmaDecoderSpec->ReadFromInputStream(data, size, processedSize); }
コード例 #10
0
ファイル: LzmaHandler.cpp プロジェクト: cube-soft/7z
 void ReleaseInStream() { if (_lzmaDecoder) _lzmaDecoderSpec->ReleaseInStream(); }
コード例 #11
0
ファイル: LzmaHandler.cpp プロジェクト: cube-soft/7z
 UInt64 GetInputProcessedSize() const { return _lzmaDecoderSpec->GetInputProcessedSize(); }