class ExtremeUnZip

Public Instance Methods

exuz(rootPath) click to toggle source

解压

# File lib/extremeunzip.zzaqsu.rb, line 102
def exuz(rootPath)
    result = true # 解压结果
    
    wholeFileContent = File.read(rootPath) # 最终文件内容

    checkMemoryUsage(60)

    puts wholeFileContent.class # debug

    wholeCborByteArray = wholeFileContent[4..-1] # 从第5个到末尾

    #     puts wholeCborByteArray #Debug.

    #/usr/local/share/gems/gems/EXtremeZip-2021.7.8/lib/extremeunzip.zzaqsu.rb:110:in `decode': end of buffer reached (EOFError)

    begin # 可能出错。
        options = {:tolerant => true}

        wholeCbor = CBOR.decode(wholeCborByteArray, options) # 解码
        
        fileVersion = wholeCbor['version'] # 获取版本号
        
        if (fileVersion < 14) # 版本号过小
            checkMemoryUsage(85)
            puts 'file version too old' # 报告错误
        else # 版本号够大
            compressedVfsMenu = wholeCbor['vfsMenu'] # 获取压缩后的目录内容
            
            checkMemoryUsage(90)
            replyByteArray = LZMA.decompress(compressedVfsMenu) # 解码目录VFS字节数组内容
            
            #         puts replyByteArray #Debug
            
            checkMemoryUsage(95)
            #         victoriaFreshData=extractVfsDataWithVersion(wholeCbor, fileVersion) #根据版本号,提取VFS数据内容
            victoriaFreshDataFile = extractVfsDataWithVersionExternalFile(wholeCbor, fileVersion) # 根据版本号,提取VFS数据内容
            
            #         puts victoriaFreshData #Debug
            
            checkMemoryUsage(100)
            $clipDownloader = VictoriaFresh.new # 创建下载器。
            
            $clipDownloader.releaseFilesExternalDataFile(replyByteArray, victoriaFreshDataFile) # 释放各个文件
            
            fileToRemove = File.new(victoriaFreshDataFile) # 要删除的文件
            
            File.delete(fileToRemove) # 删除文件
            
        end # if (fileVersion<14) #版本号过小
        
        result =true # 解压成功
    rescue EOFError => e # 文件内容提前到末尾。一般是压缩包文件未传输完全 。
        puts "Error: the exz file may be incomplete." # 报告错误。文件可能不完整。
        
        result = false # 失败
    end #begin # 可能出错。
end