[DNN学习所得]让IE也能实现解压缩功能(提供演示源码下载)
2005-07-27 11:07
781 查看
在看DNN时发现了一个很酷的功能:能通过IE浏览器实现对Zip文件的压缩和生成Zip文件文件压缩包的功能。在仔细看过程序以后发现它是调用的SharpZipLib.dll类库中的内容实现的压缩与解压功能。上网查了一下SharpZipLib,发现它居然是开源的,在http://www.icsharpcode.net网站上有下。在网站里关于SharpZipLib的源文件和调用演示包括帮助文档都有下,不过当然全是E文的。(真不知在中国有哪家公司在做.net的开源,真的十分想看国产的优秀开源项目)
在SharpZipLib中实现解压的方法(演示代码):
using System;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Data;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;
class MainClass
{
// 在控制命令行下输入要解压的Zip文件名
public static void Main(string[] args)
{
// 创建读取Zip文件对象
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
// Zip文件中的每一个文件
ZipEntry theEntry;
// 循环读取Zip文件中的每一个文件
while ((theEntry = s.GetNextEntry()) != null)
{
Console.WriteLine(theEntry.Name);
string directoryName = Path.GetDirectoryName(theEntry.Name);
<
105a5
span style="color:#0000ff;">string fileName = Path.GetFileName(theEntry.Name);
// create directory
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
// 解压文件
FileStream streamWriter = File.Create(theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
// 写入数据
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
} else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
}
}
在SharpZipLib中实现压缩的方法:
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
class MainClass
{
// 输入要压缩的文件夹和要创建的Zip文件文件名称
public static void Main(string[] args)
{
string[] filenames = Directory.GetFiles(args[0]);
Crc32 crc = new Crc32();
// 创建输出Zip文件对象
ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
// 设置压缩等级
s.SetLevel(6); // 0 - store only to 9 - means best compression
// 循环读取要压缩的文件,写入压缩包
foreach (string file in filenames)
{
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(file);
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
}
}
类中应该还有其他功能,还没有来得及看。具体SharpZipLib中是如何实行的也还没有来得及看,先试一试最简单功能,大家有兴趣可以下载看看。默认提供的演示程序是控制台下运行的(好像还有其他环境中运行的,不过我没有试),我照着做了一个WEB应用程序的,希望能对大家有用。
下载WEB下的演示程序>>
更多相关内容>>
作者Blog:http://blog.csdn.net/esshs/
在SharpZipLib中实现解压的方法(演示代码):
using System;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Data;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;
class MainClass
{
// 在控制命令行下输入要解压的Zip文件名
public static void Main(string[] args)
{
// 创建读取Zip文件对象
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
// Zip文件中的每一个文件
ZipEntry theEntry;
// 循环读取Zip文件中的每一个文件
while ((theEntry = s.GetNextEntry()) != null)
{
Console.WriteLine(theEntry.Name);
string directoryName = Path.GetDirectoryName(theEntry.Name);
<
105a5
span style="color:#0000ff;">string fileName = Path.GetFileName(theEntry.Name);
// create directory
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
// 解压文件
FileStream streamWriter = File.Create(theEntry.Name);
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
// 写入数据
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
} else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
}
}
在SharpZipLib中实现压缩的方法:
using System;
using System.IO;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
class MainClass
{
// 输入要压缩的文件夹和要创建的Zip文件文件名称
public static void Main(string[] args)
{
string[] filenames = Directory.GetFiles(args[0]);
Crc32 crc = new Crc32();
// 创建输出Zip文件对象
ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
// 设置压缩等级
s.SetLevel(6); // 0 - store only to 9 - means best compression
// 循环读取要压缩的文件,写入压缩包
foreach (string file in filenames)
{
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(file);
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();
crc.Reset();
crc.Update(buffer);
entry.Crc = crc.Value;
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
}
}
类中应该还有其他功能,还没有来得及看。具体SharpZipLib中是如何实行的也还没有来得及看,先试一试最简单功能,大家有兴趣可以下载看看。默认提供的演示程序是控制台下运行的(好像还有其他环境中运行的,不过我没有试),我照着做了一个WEB应用程序的,希望能对大家有用。
下载WEB下的演示程序>>
更多相关内容>>
作者Blog:http://blog.csdn.net/esshs/
相关文章推荐
- [DNN学习所得]让IE也能实现解压缩功能(提供演示源码下载)
- [DNN学习所得]让IE也能实现解压缩功能(提供演示源码下载)
- [DNN学习所得]让IE也能实现解压缩功能(提供演示源码下载)
- HTTP代理实现请求报文的拦截与篡改9--实现篡改功能后的演示+源码下载
- HTTP代理实现请求报文的拦截与篡改--实现篡改功能后的演示+源码下载
- Zend Framework实现具有基本功能的留言本(附demo源码下载)
- HTTP代理实现请求报文的拦截与篡改2--功能介绍+源码下载
- jQuery实现的动态文字变化输出效果示例【附演示与demo源码下载】
- Android编程实现TextView垂直自动滚动功能【附demo源码下载】
- JavaWeb学习记录(一)——response响应头之缓存设置与下载功能的实现
- ruby 网页开发框架及其源码加密技术演示,开始提供下载
- android学习——handler的学习及实现封装下载图片功能
- Datatable转换成excel并实现导出功能,导出到服务端,提供客户端下载
- PHP自定义实现微信分享朋友圈源码演示下载
- 把文件以二进制格式或base64字符串形式保存到数据库中,并实现下载功能源码
- TensorFlow (RNN)深度学习 双向LSTM(BiLSTM)+CRF 实现 sequence labeling 序列标注问题 源码下载
- 微信小程序实现点击按钮修改文字大小功能【附demo源码下载】
- ios 画图 绘图的实现(自由批注中视图的subview的实现)bitmap Quartz 2D 缓存位图 自由批注功能的实现 如何实现在view上自由绘图 提供源码
- C# UDP通信实现(提供源码下载)
- 微信小程序实现的涂鸦功能示例【附源码下载】