一个优化后的压缩算法(下)

这是一个关于类中压缩和解压算法的详细实现过程。代码包括读取输入文件,使用特定的数据结构和优化方法进行压缩,然后将结果写入临时文件。算法涉及到内存管理、文件操作、位操作和缓冲区管理,确保高效地处理文件数据。
摘要由CSDN通过智能技术生成

'类中压缩与解压算法

Private Sub Compress()
    Dim lngTemp As Long, intCount As Integer
    Dim intBufferLocation As Integer
    Dim intMaxLen As Integer
    Dim intNext As Integer
    Dim intPrev As Integer
    Dim intMatchPos As Integer
    Dim intMatchLen As Integer
    Dim intInputFile As Integer
    Dim intOutputFile As Integer
    Dim aintWindowNext(mcintWindowSize + 1 + mcintWindowSize) As Integer
    Dim aintWindowPrev(mcintWindowSize + 1) As Integer
    Dim intByteCodeWritten As Long
    Dim intBitCount As Integer
    Dim abytWindow(mcintWindowSize + mcintMaxMatchLen) As Byte
    Dim udtFileH As FileHeader
    Dim strOutTmpFile As String
    Dim lngBytesRead As Long
    Dim lngFileLength As Long
    Dim lngCurWritten As Long
    Dim lngInBufLen As Long, abytInputBuffer() As Byte, abytOutputBuffer() As Byte
    Dim lngOutBufLen As Long, lngInPos As Long, lngOutPos As Long
    Dim intErrNo As Integer
    On Error GoTo PROC_ERR
    m_bEnableProcss = True
    If Len(Dir(m_strInputFileName)) = 0 Or Len(m_strInputFileName) = 0 Then intErrNo = 1: GoTo PROC_ERR
    If Len(m_strOutputFileName) = 0 Then m_strOutputFileName = m_strInputFileName
    strOutTmpFile = m_strOutputFileName & ".tmp"
    If Len(Dir(strOutTmpFile)) > 0 Then Kill strOutTmpFile
    If FileLen(m_strInputFileName) < 100 Then intErrNo = 2:  GoTo PROC_ERR
    intInputFile = FreeFile
    Open m_strInputFileName For Binary Access Read As intInputFile
        Get intInputFile, , udtFileH
        Seek #intInputFile, 1
        If udtFileH.HeaderTag = mcstrSignature Then intErrNo = 3:  GoTo PROC_ERR
        intOutputFile = FreeFile
        Open strOutTmpFile For Binary As intOutputFile
            For intCount = 0 To mcintWindowSize
                aintWindowPrev(intCount) = mcintNull
                abytWindow(intCount) = &H20
            Next
            CopyMemory aintWindowNext(0), aintWindowPrev(0), (mcintWindowSize + 1) * 2
            CopyMemory aintWindowNext(mcintWindowSize + 1), aintWindowPrev(0), mcintWindowSize * 2
            CopyMemory abytWindow(mcintWindowSize + 1), abytWindow(0), mcintMaxMatchLen - 1
            intByteCodeWritten = 1
            lngFileLength = LOF(intInputFile)
            lngInBufLen = &HA000&
            lngOutBufLen = &HA000&
            If lngInBufLen > lngFileLength Then lngInBufLen = lngFileLength
            ReDim abytInputBuffer(lngInBufLen - 1)
            ReDim abytOutputBuffer(lngOutBufLen + 17)
            With udtFileH
                .HeaderSize = Len(udtFileH)
                lngCurWritten = .HeaderSize + 1
                .HeaderTag = mcstrSignature
                .FileLength = lngFileLength
                .Version = App.Revision
                .Flag = 0
            End With
            intMaxLen = mcintMaxMatchLen
            lngBytesRead = mcintMaxMatchLen
            lngInPos = mcintMaxMatchLen
            intBitCount = 1
            Put intOutputFile, , udtFileH
            Get intInputFile, , abytInputBuffer
            CopyMemory abytWindow(0), abytInputBuffer(0), mcintMaxMatchLen
            CopyMemory abytWindow(mcintWindowSize), abytInputBuffer(0), mcintMaxMatchLen
            Do While intMaxLen
                intMatchPos = 0
                intMatchLen = 0
                intPrev = aintWindowNext(((&H100& * abytWindow(intBufferLocation + 1) + abytWindow(intBufferLocation)) And &HFFF) + mcintWindowSize + 1)
                intCount 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值