📄 zlibinstream.cpp
字号:
/* Copyright (C) 2006 Lucas Gomez All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// INCLUDE FILES
#include "ZLibInStream.h"
#include "VncViewer.pan"
//LITERALS
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// ZLibInStream::ZLibInStream()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
ZLibInStream::ZLibInStream(TInt aBufSize)
{
iBufSize=aBufSize;
iBuf.CreateMaxL(iBufSize);
iPtr=iEnd=iPtrOffset=0;
iInflater=CEZDecompressor::NewL(*this);
}
// ---------------------------------------------------------------------------
// ZLibInStream::~ZLibInStream()
// Destructor.
// ---------------------------------------------------------------------------
//
ZLibInStream::~ZLibInStream()
{
if(iInflater!=NULL)
{
delete iInflater;
iInflater=NULL;
}
}
void ZLibInStream::SetUnderlying(InStream* aIS,TInt aBytesIn)
{
iUnderlying=aIS;
iBytesIn=aBytesIn;
iPtr=iEnd=0;
}
void ZLibInStream::Reset()
{
iPtr=iEnd=0;
if(iUnderlying==NULL) return;
while(iBytesIn>0)
{
Decompress();
iEnd=0;
}
delete iUnderlying;
iUnderlying=NULL;
}
TInt ZLibInStream::Pos()
{
return iPtrOffset+iPtr;
}
TInt ZLibInStream::Overrun(TInt aItemSize,TInt aNItems)
{
if(aItemSize>iBufSize)
User::Leave(EVncViewerZLibInStreamOverrun);
if(iUnderlying==NULL)
User::Leave(EVncViewerZLibInStreamOverrun);
if(iEnd-iPtr!=0)
{
iBuf.Copy(iBuf.Mid(iPtr,iEnd-iPtr));
iBuf.SetMax();
}
iPtrOffset+=iPtr;
iEnd-=iPtr;
iPtr=0;
while(iEnd<aItemSize)
Decompress();
if(aItemSize*aNItems>iEnd)
aNItems=iEnd/aItemSize;
return aNItems;
}
void ZLibInStream::Decompress()
{
iUnderlying->Check(1);
TInt avail_in=iUnderlying->GetEnd()-iUnderlying->GetPtr();
if(avail_in>iBytesIn)
avail_in=iBytesIn;
TPtrC8 input(iUnderlying->GetBuf().Mid(iUnderlying->GetPtr(),avail_in));
TInt asco=input.Length();
TPtr8 output(iBuf.MidTPtr(iEnd,iBufSize-iEnd));
output.Zero();
iInflater->SetInput(input);
iInflater->SetOutput(output);
TBool moreData=iInflater->InflateL();
iEnd+=iInflater->AvailOut();
if(moreData)
{
iBytesIn-=avail_in;
iUnderlying->SetPtr(iUnderlying->GetPtr()+avail_in);
}
}
void ZLibInStream::InitializeL(CEZZStream& /*aZStream*/)
{
}
void ZLibInStream::NeedInputL(CEZZStream& aZStream)
{
TInt avail_in=iUnderlying->GetEnd()-iUnderlying->GetPtr();
if(avail_in>iBytesIn)
avail_in=iBytesIn;
TPtrC8 input(iUnderlying->GetBuf().Mid(iUnderlying->GetPtr(),avail_in));
aZStream.SetInput(input);
}
void ZLibInStream::NeedOutputL(CEZZStream& aZStream)
{
TPtr8 output(iBuf.MidTPtr(iEnd,iBufSize-iEnd));
output.Zero();
aZStream.SetOutput(output);
}
void ZLibInStream::FinalizeL(CEZZStream& /*aZStream*/)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -