最近写一个程序,用到很多小文件,这些小文件不能合并,但是要在程序中调用,于是想把这些小文件放在压缩包内,需要的时候在从里面取,程序中产生的文件可以往压缩包内放。请问实现这些功能的方法?实现该功能过程中不要产生临时文件最好。
经过一番搜索发现了zlib和infozip,但是我不太懂C,其实也就是能看懂简单的C程序,找了一些别人编译的dll,其中一个是LiteZip/LiteUnzip(http://forum.csdn.net/PointForum/Forum/PostTopic.aspx?forumID=33fa67ff-a665-455a-8789-c5b59c9d8d5a),用法比较简单,但是我测试时发现可以按照说明创建空压缩文件,但往里面添加文件时,VB6就出现了错误,直接退出了,请大家看看是怎么回事?另外还有没有其它方法实现这个功能,最好是基于zlib和infozip,如能像LiteZip/LiteUnzip提供dll或控件非常感谢。不知道有没有用VB实现压缩和解压的代码如果觉得分数不够,我可以再加。

解决方案 »

  1.   

    怎么才能修改帖子呢?这是我的源代码
    Option Explicit
    Private Declare Function ZipCreateFile Lib "litezip" Alias "ZipCreateFileA" (ByRef hZip As Long, ByVal filename As String, ByVal password As String) As Long
    Private Declare Function ZipAddFile Lib "litezip" Alias "ZipAddFileA" (ByVal hZip As Long, ByVal filename As String) As Long
    Private Declare Function ZipClose Lib "litezip" (ByVal hZip As Long) As Long
    Private Declare Function ZipCreateBuffer Lib "litezip" (hZip As Long, ByVal lpBuffer As Long, ByVal size As Long, password As String) As Long
    Private Declare Function ZipCreateHandle Lib "litezip" (hZip As Long, ByVal fileHandle As Long, password As String) As Long
    Private Declare Function ZipAddHandle Lib "litezip" Alias "ZipAddHandleA" (ByVal hZip As Long, zipname As String, ByVal fileHandle As Long) As Long
    Private Declare Function ZipAddBuffer Lib "litezip" Alias "ZipAddBufferA" (ByVal hZip As Long, zipname As String, ByVal lpBuffer As Long, ByVal size As Long) As Long
    Private Declare Function ZipAddPipe Lib "litezip" Alias "ZipAddPipeA" (ByVal hZip As Long, zipname As String, ByVal fileHandle As Long, ByVal size As Long) As Long
    Private Declare Function ZipAddFolder Lib "litezip" Alias "ZipAddFolderA" (ByVal hZip As Long, zipname As String) As Long
    Private Declare Function ZipGetMemory Lib "litezip" (ByVal hZip As Long, bufferPtr As Long, size As Long, freeHandle As Long) As Long
    Private Declare Function ZipResetMemory Lib "litezip" (ByVal hZip As Long) As Long
    Private Declare Function ZipOptions Lib "litezip" (ByVal hZip As Long, ByVal flags As Long) As Long
    Private Declare Function ZipFormatMessage Lib "litezip" Alias "ZipFormatMessageA" (ByVal errornumber As Long, lpBuffer As String, ByVal buffersize As Long) As Long
    Private Declare Function ZipAddDir Lib "litezip" Alias "ZipAddDirA" (ByVal hZip As Long, dirname As String, ByVal offset As Long) As Long
    Private Sub Form_Click()
        Dim iii As Long, hhzip As Long, jjj As Long
        iii = ZipCreateFile(hhzip, "E:\Work-Temp\VB小程序\ZlibTool1\tttt.zip", 0)
        jjj = ZipAddFile(hhzip, "E:\Work-Temp\VB小程序\ZlibTool1\test.jpg")
    End Sub
      

  2.   

    楼上的:如何设计一个集成包呢,说实话VB还有很多东西我不懂
    这个Dll在VB2005中没有任何问题,可以实现,但是我对2005现在还不熟悉,因此这个程序比较急,等熟悉了VB2005,用6都做出来,唉
      

  3.   

    我也不会VB,我至少6年不用了,最近想起以前用过VB,所谓的包其实道理简单,假设有很大一个文件,你要处理他的内容,整个文件可能变大可能变小,最简单的做法自然是处理了一部分文件的内容后存入一个新的文件,循环直到源文件都被你处理完。举个例子就是,你要替代文件中的"windows"为"microsoft windows",你自然是一个一个读出来单词,如果是"windows"就换成"microsoft windows",然后存入到一个新文件中,直到整个文件处理完。假设这个方法叫方法A。现在假设有多个文件file1-100,你可能只处理file1, file5, file99这三个,且这100个文件被集成到了一个大文件中,可以将大文件按需要分为100块,分别称为file1....file100,如果要更新file1,那要先将file1的内容提出来,按方法A修改。处理完了file1,再处理大文件,方法仍然是方法A。
      

  4.   

    你这种方法好像可行。不知道如何才能集成为一个文件?我的许多小文件是文本的,但是内容有特殊格式和特定内容,并以单个文件的形式存放,然后通过另外一个dll调用,并以特殊的图形形式显示出来,并可修改图形,可以将这种图形以文本的形式存入文件中。因此,小文件中的内容是不能错的。本人觉得还是利用类似zlib和infozip的方法比较稳妥,处理起来简单吧,就是不知道这个dll重新编译一下能不能不出错呢。
      

  5.   

    那方法当然简单,不过用的别的人代码,不太保险,最好再找一个更稳定的dll。
      

  6.   

    用RB的话直接用VirtualVolumn创建个虚拟卷。用VB嘛,只要支持Windows就没那么麻烦了,用unRar的dll都行,不需要压缩只要把压缩等级设置下就可以了。