📄 class1.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;
using Core.Services.Sdk;
using System.Windows.Forms;
namespace GZiplib
{
[Plugin(true)]
public class Class1:IPlugin
{
private PluginInfo p;
private int curr = 0, max = 0;
public Class1()
{
p = new PluginInfo("GZip compress", "Signercompress", "使用Gzip压缩文件", new Version(1, 0, 3204, 24355), new ToolStripMenuItem("Gzip压缩"));
}
public static void CompressBytes(FileStream inf,FileStream outf)
{
byte[] data = new byte[inf.Length];
inf.Read(data, 0, data.Length);
MemoryStream output = new MemoryStream();
GZipStream gzip = new GZipStream(output,
CompressionMode.Compress, true);
gzip.Write(data, 0, data.Length);
gzip.Close();
outf.Write(output.ToArray(),0,(int)output.Length);
}
#region IPlugin 成员
public void AssignTask(System.Collections.ArrayList Targets)
{
foreach (string s in Targets)
max += (int)(new FileInfo(s).Length);
foreach (string s in Targets)
{
FileInfo fi = new FileInfo(s);
curr += (int)fi.Length;
string name = s.Remove(s.LastIndexOf(".")) + ".gzip";
FileStream fs = new FileStream(name, FileMode.Create);//output
CompressBytes(fi.OpenRead(), fs);
OnProgressChanged(new ProgressChangedEventArgs(curr, max));
}
}
public PluginInfo PluginInfo
{
get
{
return p;
}
}
public event ProgressChangedEventHandler ProgressChanged;
protected virtual void OnProgressChanged(ProgressChangedEventArgs e)
{
if (ProgressChanged != null)
{
ProgressChanged(this, e);
}
}
#endregion
#region IDisposable 成员
public void Dispose()
{
}
#endregion
}
[Plugin(true)]
public class Class2 : IPlugin
{
private PluginInfo p;
private int curr = 0, max = 0;
public Class2()
{
p = new PluginInfo("GZip decompress", "Signercompress", "使用Gzip解压缩文件", new Version(1, 0, 3204, 24355), new ToolStripMenuItem("Gzip解压"));
}
public static void DecompressBytes(byte[] inf,FileStream outf)
{
MemoryStream input = new MemoryStream();
input.Write(inf, 0, inf.Length);
input.Position = 0;
GZipStream gzip = new GZipStream(input, CompressionMode.Decompress, false);
MemoryStream output = new MemoryStream();
byte[] buff = new byte[4096];
int read = -1;
read = gzip.Read(buff, 0, buff.Length);
while (read > 0)
{
output.Write(buff, 0, read);
read = gzip.Read(buff, 0, buff.Length);
}
gzip.Close();
outf.Write(output.ToArray(),0,(int)output.Length);
}
#region IPlugin 成员
public void AssignTask(System.Collections.ArrayList Targets)
{
foreach (string s in Targets)
max += (int)(new FileInfo(s).Length);
foreach (string s in Targets)
{
FileStream fs = new FileStream(s, FileMode.Open);
curr += (int)fs.Length;
byte[] buff = new byte[fs.Length];
fs.Read(buff, 0, (int)fs.Length);
fs.Close();
DecompressBytes(buff, new FileStream(s.Remove(s.LastIndexOf(".")), FileMode.Create));
OnProgressChanged(new ProgressChangedEventArgs(curr, max));
}
}
public PluginInfo PluginInfo
{
get
{
return p;
}
}
public event ProgressChangedEventHandler ProgressChanged;
protected virtual void OnProgressChanged(ProgressChangedEventArgs e)
{
if (ProgressChanged != null)
{
ProgressChanged(this, e);
}
}
#endregion
#region IDisposable 成员
public void Dispose()
{
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -