




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
与WinRAR以最快方式压缩ZIP比较, 255M的文件 Level=0时用时24.98秒大小95.1M Level=255时用时30.24秒大小91.6M WinRAR最快压缩ZIP用时25.2秒大小58.6M 标准RAR压缩,我看了一下,实在太慢,也就没试了,估计要几分钟才会有结果。 从速度看,基本持平了,这个算法虽然最大压缩能力有限,但感觉设计得很巧妙,每次都基于动态表,使软件可以做得很小巧,资源占用也很少。非常值得收藏! 测试窗体中的代码 OptionExplicit PrivateWithEventsObjZipAsClassZip PrivateBgTimeAsSingle PrivateSubCommand1_Click() BgTime=Timer Command1.Enabled=False Command2.Enabled=False WithObjZip .InputFileName=Text1.Text .OutputFileName=Text2.Text .IsCompress=True .CompressLevel=Val(Text4.Text) .BeginProcss EndWith Label1.Caption=Round(Timer-BgTime,2)&秒 Command1.Enabled=True Command2.Enabled=True EndSub PrivateSubCommand2_Click() BgTime=Timer Command1.Enabled=False Command2.Enabled=False WithObjZip .InputFileName=Text2.Text .OutputFileName=Text3.Text .IsCompress=False .BeginProcss EndWith Label1=Round(Timer-BgTime,2)&秒 Command1.Enabled=True Command2.Enabled=True EndSub PrivateSubCommand3_Click() ObjZip.CancelProcss=True EndSubPrivateSubForm_Load() SetObjZip=NewClassZip Command1.Caption=压缩 Command2.Caption=解压 Command3.Caption=中断 EndSub PrivateSubForm_Unload(CancelAsInteger) SetObjZip=Nothing EndSub PrivateSubObjZip_FileProgress(sngPercentageAsSingle) Label1=Int(sngPercentage*100)&% EndSub PrivateSubObjZip_ProcssError(ErrorDescriptionAsString) MsgBoxErrorDescription EndSubClassZip类中的声明与属性、方法、事件 OptionExplicit PublicEventFileProgress(sngPercentageAsSingle) PublicEventProcssError(ErrorDescriptionAsString) PrivateTypeFileHeader HeaderTagAsString*3 HeaderSizeAsInteger FlagAsByte FileLengthAsLong VersionAsInteger EndType PrivatemintCompressLevelAsLong Privatem_bEnableProcssAsBoolean Privatem_bCompressAsBoolean Privatem_strInputFileNameAsString Privatem_strOutputFileNameAsString PrivateConstmcintWindowSizeAsInteger=&H1000 PrivateConstmcintMaxMatchLenAsInteger=18 PrivateConstmcintMinMatchLenAsInteger=3 PrivateConstmcintNullAsLong=&H1000 PrivateConstmcstrSignatureAsString=FMZ PrivateDeclareSubCopyMemoryLibKernel32AliasRtlMoveMemory(pDestAsAny,pSourceAsAny,ByValdwLengthAsLong)PublicSubBeginProcss() Ifm_bCompressThen Compress Else Decompress EndIf EndSub PrivateFunctionLastError(ErrNoAsInteger)AsString SelectCaseErrNo Case1 LastError=待压缩文件未设置或不存在 Case2 LastError=待压缩文件长度太小 Case3 LastError=待压缩文件已经过压缩 Case4 LastError=待解压文件未设置或不存在 Case5 LastError=待解压文件格式不对或为本软件不能认别的高版本软件所压缩 Case254 LastError=用户取消了操作 Case255 LastError=未知错误 EndSelect EndFunction PublicPropertyGetCompressLevel()AsInteger CompressLevel=mintCompressLevel16 EndProperty PublicPropertyLetCompressLevel(ByValintValueAsInteger) mintCompressLevel=intValue*16 IfmintCompressLevel0ThenKillstrOutTmpFile IfFileLen(m_strInputFileName)lngFileLengthThenlngInBufLen=lngFileLength ReDimabytInputBuffer(lngInBufLen-1) ReDimabytOutputBuffer(lngOutBufLen+17) WithudtFileH .HeaderSize=Len(udtFileH) lngCurWritten=.HeaderSize+1 .HeaderTag=mcstrSignature .FileLength=lngFileLength .Version=App.Revision .Flag=0 EndWith intMaxLen=mcintMaxMatchLen lngBytesRead=mcintMaxMatchLen lngInPos=mcintMaxMatchLen intBitCount=1 PutintOutputFile,udtFileH GetintInputFile,abytInputBuffer CopyMemoryabytWindow(0),abytInputBuffer(0),mcintMaxMatchLen CopyMemoryabytWindow(mcintWindowSize),abytInputBuffer(0),mcintMaxMatchLenDoWhileintMaxLen intMatchPos=0 intMatchLen=0 intPrev=aintWindowNext(&H100&*abytWindow(intBufferLocation+1)+abytWindow(intBufferLocation)And&HFFF)+mcintWindowSize+1) intCount=0 DoUntilintCountmintCompressLevelOrintPrev=mcintNull intNext=0 DoWhile(abytWindow(intPrev+intNext)=abytWindow(intBufferLocation+intNext)AndintNextintMatchLenThen intMatchLen=intNext intMatchPos=intPrev IfintNext=mcintMaxMatchLenThen aintWindowNext(aintWindowPrev(intPrev)=aintWindowNext(intPrev) aintWindowPrev(aintWindowNext(intPrev)=aintWindowPrev(intPrev) aintWindowNext(intPrev)=mcintNull aintWindowPrev(intPrev)=mcintNull ExitDo EndIf EndIf intPrev=aintWindowNext(intPrev) intCount=intCount+1 Loop IfintBitCountAnd&H100Then lngOutPos=intByteCodeWritten IfintByteCodeWrittenlngOutBufLenThen PutintOutputFile,lngCurWritten,abytOutputBuffer DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR lngCurWritten=lngCurWritten+intByteCodeWritten lngOutPos=0 EndIf intByteCodeWritten=lngOutPos+1 intBitCount=1 abytOutputBuffer(lngOutPos)=0 EndIf IfintMatchLen1Then IfintMatchLenintMaxLenThenintMatchLen=intMaxLen abytOutputBuffer(intByteCodeWritten)=intMatchPosAnd&HFF intByteCodeWritten=intByteCodeWritten+1 abytOutputBuffer(intByteCodeWritten)=(intMatchPos16)And&HF0)OrintMatchLen-mcintMinMatchLen)And&HFF EndIf intByteCodeWritten=intByteCodeWritten+1 intBitCount=intBitCount*2DoWhileintMatchLen intPrev=intBufferLocation+mcintMaxMatchLen intNext=intPrevAnd&HFFF IfaintWindowPrev(intNext)mcintNullThen aintWindowNext(aintWindowPrev(intNext)=aintWindowNext(intNext) aintWindowPrev(aintWindowNext(intNext)=aintWindowPrev(intNext) aintWindowNext(intNext)=mcintNull aintWindowPrev(intNext)=mcintNull EndIf IflngInPos=mcintWindowSizeThenabytWindow(intPrev)=abytInputBuffer(lngInPos) lngBytesRead=lngBytesRead+1 lngInPos=lngInPos+1 IflngInPos=lngInBufLenThen IflngFileLengthlngBytesReadThen IflngInBufLenlngFileLength-lngBytesReadThen lngInBufLen=lngFileLength-lngBytesRead ReDimabytInputBuffer(lngInBufLen-1) EndIf GetintInputFile,abytInputBuffer lngInPos=0 RaiseEventFileProgress(lngBytesRead/lngFileLength) DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR EndIf EndIf EndIf intPrev=(&H100&*abytWindow(intBufferLocation+1)+abytWindow(intBufferLocation)And&HFFF)+mcintWindowSize+1 intNext=aintWindowNext(intPrev) aintWindowPrev(intBufferLocation)=intPrev aintWindowNext(intBufferLocation)=intNext aintWindowNext(intPrev)=intBufferLocation IfintNextmcintNullThenaintWindowPrev(intNext)=intBufferLocation intBufferLocation=(intBufferLocation+1)And&HFFF intMatchLen=intMatchLen-1 Loop IflngInPos=lngInBufLenThenintMaxLen=intMaxLen-1 Loop IfintByteCodeWritten0Then ReDimPreserveabytOutputBuffer(intByteCodeWritten-1) PutintOutputFile,lngCurWritten,abytOutputBuffer EndIf CloseintInputFile CloseintOutputFile IfLen(Dir(m_strOutputFileName)0ThenKillm_strOutputFileName NamestrOutTmpFileAsm_strOutputFileName RaiseEventFileProgress(1) ExitSub PROC_ERR: CloseintOutputFile CloseintInputFile IfLen(Dir(strOutTmpFile)0AndLen(strOutTmpFile)0ThenKillstrOutTmpFile IfintErrNo=0ThenintErrNo=255 RaiseEventProcssError(LastError(intErrNo) EndSubPrivateSubDecompress() DimintTempAsInteger DimintBufferLocationAsInteger DimintLengthAsInteger DimbytHiByteAsInteger DimbytLoByteAsInteger DimintWindowPositionAsInteger DimlngFlagsAsLong DimintInputFileAsInteger DimintOutputFileAsInteger DimabytWindow(mcintWindowSize+mcintMaxMatchLen)AsByte DimstrOutTmpFileAsString DimlngBytesReadAsLong DimlngBytesWrittenAsLong DimlngFileLengthAsLong DimlngOriginalFileLenAsLong DimlngInBufLenAsLong,abytInBuf()AsByte,abytOutBuf()AsByte DimlngOutBufLenAsLong,lngInPosAsLong,lngOutPosAsLong DimudtFileHAsFileHeader DimintErrNoAsInteger OnErrorGoToPROC_ERR m_bEnableProcss=True IfLen(Dir(m_strInputFileName)=0OrLen(m_strInputFileName)=0ThenintErrNo=4:GoToPROC_ERR IfLen(m_strOutputFileName)=0Thenm_strOutputFileName=m_strInputFileName strOutTmpFile=m_strOutputFileName&.tmp IfLen(Dir(strOutTmpFile)0ThenKillstrOutTmpFile intInputFile=FreeFile Openm_strInputFileNameForBinaryAccessReadAsintInputFile lngFileLength=LOF(intInputFile) GetintInputFile,udtFileH IfudtFileH.HeaderTag=mcstrSignatureAndudtFileH.VersionlngFileLengthThenlngInBufLen=lngFileLength ReDimabytInBuf(lngInBufLen-1) ReDimabytOutBuf(lngOutBufLen-1) GetintInputFile,abytInBuf DoWhilelngBytesWritten=lngInBufLenThen IflngFileLengthlngBytesReadThen IflngInBufLenlngFileLength-lngBytesReadThen lngInBufLen=lngFileLength-lngBytesRead ReDimabytInBuf(lngInBufLen-1) EndIf GetintInputFile,abytInBuf DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR lngInPos=0 EndIf EndIf EndIfIf(lngFlagsAnd1)Then abytWindow(intWindowPosition)=abytInBuf(lngInPos) abytOutBuf(lngOutPos)=abytInBuf(lngInPos) lngBytesRead=lngBytesRead+1 lngInPos=lngInPos+1 lngBytesWritten=lngBytesWritten+1 lngOutPos=lngOutPos+1 intWindowPosition=(intWindowPosition+1)And&HFFF IflngInPos=lngInBufLenThen IflngFileLengthlngBytesReadThen IflngInBufLenlngFileLength-lngBytesReadThen lngInBufLen=lngFileLength-lngBytesRead ReDimabytInBuf(lngInBufLen-1) EndIf GetintInputFile,abytInBuf DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR lngInPos=0 EndIf EndIf IflngOutPos=lngOutBufLenThen PutintOutputFile,abytOutBuf lngOutPos=0 RaiseEventFileProgress(lngBytesWritten/lngOriginalFileLen) DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR EndIf Else bytHiByte=abytInBuf(lngInPos) lngBytesRead=lngBytesRead+1 lngInPos=lngInPos+1 IflngInPos=lngInBufLenThen IflngFileLengthlngBytesReadThen IflngInBufLenlngFileLength-lngBytesReadThen lngInBufLen=lngFileLength-lngBytesRead ReDimabytInBuf(lngInBufLen-1) EndIf GetintInputFile,abytInBuf DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR lngInPos=0 EndIf EndIf bytLoByte=abytInBuf(lngInPos) intBufferLocation=(bytLoByteAnd&HF0)*16+bytHiByte)And&HFFF intLength=(bytLoByteAnd&HF)+mcintMinMatchLen lngBytesRead=lngBytesRead+1 lngInPos=lngInPos+1 IflngInPos=lngInBufLenThen IflngFileLengthlngBytesReadThen IflngInBufLenlngFileLength-lngBytesReadThen lngInBufLen=lngFileLength-lngBytesRead ReDimabytInBuf(lngInBufLen-1) EndIf GetintInputFile,abytInBuf DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR lngInPos=0 EndIf EndIfintTemp=intBufferLocation+intLength DoWhileintBufferLocation=lngOutBufLenThen PutintOutputFile,abytOutBuf lngOutPos=0 RaiseEventFileProgress(lngBytesWritten/lngOriginalFileLen) DoEvents Ifm_bEnableProcss=FalseThenintErrNo=254:GoToPROC_ERR EndIf Loop EndIf Loop IflngOutPos0Then ReDimPreserveabytOutBuf(lngOutPos-1) PutintOutputFile,abytOutBuf EndIf CloseintOutputFile Else intErrNo=5 GoToPROC_ERR EndIf CloseintInputFile IfLen(Dir(m_strOutputFileName)0ThenKillm_strOutputFileName NamestrOutTmpFileAsm_strOutputFileName RaiseEventFileProgress(1) ExitSub PROC_ERR: CloseintOutputFile CloseintInputFile IfLen(Dir(strOutTmpFile)0AndLen(strOutTmpFile)0ThenKillstrOutTmpFile IfintErrNo=0ThenintErrNo=255 RaiseEventProcssError(LastError(intErrNo) EndSubClassZip类中的声明与属性、方法、事件 OptionExplicit PublicEventFileProgress(sngPercentageAsSingle) PublicEventProcssError(ErrorDescriptionAsString) PrivateTypeFileHeader HeaderTagAsString*3 HeaderSizeAsInteger FlagAsByte FileLengthAsLong VersionAsInteger EndType PrivatemintCompressLevelAsLong Privatem_bEnableProcssAsBoolean Privatem_bCompressAsBoolean Privatem_strInputFileNameAsString Privatem_strOutputFileNameAsString PrivateConstmcintWindowSizeAsInteger=&H1000 PrivateConstmcintMaxMatchLenAsInteger=18 PrivateConstmcintMinMatchLenAsInteger=3 PrivateConstmcintNullAsLong=&H1000 PrivateConstmcstrSignatureAsString=FMZ PrivateDeclareSubCopyMemoryLibKernel32AliasRtlMoveMemory(pDestAsAny,pSourceAsAny,ByValdwLengthAsLong) PublicSubBeginProcss() Ifm_bCompressThen Compress Else Decompress EndIf EndSub PrivateFunctionLastError(ErrNoAsInteger)AsString SelectCaseErrNo Case1 LastError=待压缩文件未设置或不存在 Case2 LastError=待压缩文件长度太小 Case3 LastError=待压缩文件已经过压缩 Case4 LastError=待解压文件未设置或不存在 Case5 LastError=待解压文件格式不对或为本软件不能认别的高版本软件所压缩 Case254 LastError=用户取消了操作 Case255 LastError=未知错误 EndSelect EndFunction PublicPropertyGetCompressLevel()AsInteger CompressLevel=mintCompressLevel16 EndProperty PublicPropertyLetCompressLevel(ByValintValueAsInteger) mintCompressLevel=intValue*16 IfmintCompressLevel0ThenmintCompressLevel=0 EndProperty PublicPropertyGetIsCompress()AsBoolean IsCompress=m_bCompress EndProperty PublicPropertyLetIsCompress(ByValbValueAsBoolean) m_bCompress=bValue EndProperty PublicPropertyLetCancelProcss(ByValbValueAsBoolean) m_bEnableProcss=NotbValue EndProperty PublicPropertyGetInputFileName()AsSt
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度跨境电商物流仓储配送一体化服务协议
- 2025科技博览会场地租赁及技术支持服务合同
- 2025年可再生能源项目招标投标实施与保障合同
- 2025年度医疗保健行业员工聘任协议书样本
- 2025年跨境电商物流车辆租赁与运输人员培训服务协议
- 2025年节能环保汽车零部件加工技术保密协议书
- 2025全球医疗器械市场拓展合作框架协议
- 2025现代农业科技企业专项资金互助贷款合同范本
- 家庭农场与合作社业务合作协议
- 2025年智能穿戴设备定制生产及销售合作协议
- 2025-2030中国光耦元件市场竞争风险及发展态势分析报告
- 2025年中州水务财务笔试题及答案
- 公交交警安全知识培训课件
- (标准)仓库退租协议书
- 2025年国际法律合规与跨境经营风险试题及答案
- 脊髓损伤的康复课件
- 配电线路运维培训课件
- 初级健康照护师课件
- 酒店股东消费管理办法
- 《慢性萎缩性胃炎中西医结合诊疗专家共识(2025)》解读
- 新解读《碳纤维电热供暖系统应用技术规程 T-CCES 13 - 2020》解读
评论
0/150
提交评论