惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
Google Developers Blog
S
SegmentFault 最新的问题
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
P
Proofpoint News Feed
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
博客园_首页
I
InfoQ
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
美团技术团队
Vercel News
Vercel News
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - fisherman

学习写第一个SQL server触发器 操纵自如--页面内的配合与通信 一些DIV+CSS 命名规范 asp.net 2.0中生成RSS 避免重复提交 - fisherman - 博客园 button 删除确认 - fisherman - 博客园 用相对定位和负向移动完成图片象框阴影 负边距居中法(水平居中、垂直居中) - fisherman - 博客园 CSS 代码格式化工具 - fisherman - 博客园 JS代码的格式化和压缩 - fisherman - 博客园 把SQL SERVER里表里的数据导出成为insert into 脚本 对FckEditor编辑器在MAXTHON浏览器下选择服务器文件对话框显示不正常的改进 下载网页中远程图片的方法 读取marc数据 关于ISO2709数据的格式说明 C#写的读取ISO2709格式数据的DLL 数据库打开 使用 Engine 对象创建 SQL Server Compact Edition 数据库 Access数据库压缩和修复
用SharpZipLib压缩和解压缩文件
fisherman · 2007-05-30 · via 博客园 - fisherman


第一步:添加引用文件:
ICSharpCode.SharpZipLib.dll

第二步:导入名称空间:Imports ICSharpCode.SharpZipLib.Zip

第三步:a、压缩函数

'<summary>
    ' Create a zip archive.
    ' </summary>
    ' <param name="filename">The filename.</param>
    ' <param name="directory">The directory to zip.</param> 
    Public Shared Sub PackFiles(ByVal filename As StringByVal directory As String)
        
Try
            
Dim fz As FastZip = New FastZip()
            fz.CreateEmptyDirectories 
= True
            fz.CreateZip(filename, directory, 
True"")
            fz 
= Nothing
        
Catch
            
Throw
        
End Try
End Sub

       b、解压缩文件

'<summary>
    'Unpacks the files.
    '</summary>
    '<param name="file">The file.</param>
    '<returns>if succeed return true,otherwise false.</returns>
    Public Shared Function UnpackFiles(ByVal file As StringByVal dir As StringAs Boolean
        
Try
            
'
            If Not Directory.Exists(dirThen
                Directory.CreateDirectory(
dir)
            
End If
            
Dim s As ZipInputStream = New ZipInputStream(IO.File.OpenRead(file))
            
Dim theEntry As ZipEntry
            theEntry 
= s.GetNextEntry()

            
While Not IsNothing(theEntry)

                
Dim directoryName As String = Path.GetDirectoryName(theEntry.Name)
                
Dim fileName As String = Path.GetFileName(theEntry.Name)

                
If directoryName <> String.Empty Then
                    Directory.CreateDirectory(
dir + directoryName)
                
End If



                
If fileName <> String.Empty Then
                    
Dim StreamWriter As FileStream = IO.File.Create(dir + theEntry.Name)

                    
Dim Size As Integer = 2048
                    
Dim data(2048As Byte
                    
While (True)
                        Size 
= s.Read(data, 0, data.Length)
                        
If Size > 0 Then
                            StreamWriter.Write(data, 
0, Size)
                        
Else
                            
Exit While
                        
End If
                    
End While

                    StreamWriter.Close()
                
End If
                
'
                theEntry = s.GetNextEntry()
            
End While
            s.Close()
            
Return True
        
Catch ex As Exception
            
Throw
        
End Try
    
End Function

实例图:

点击下载