本文整理汇总了C#中ICSharpCode.SharpZipLib.GZip.GZipOutputStream类的典型用法代码示例。如果您正苦于以下问题:C# GZipOutputStream类的具体用法?C# GZipOutputStream怎么用?C# GZipOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GZipOutputStream类属于ICSharpCode.SharpZipLib.GZip命名空间,在下文中一共展示了GZipOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGZip
public void TestGZip()
{
MemoryStream ms = new MemoryStream();
GZipOutputStream outStream = new GZipOutputStream(ms);
byte[] buf = new byte[100000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Flush();
outStream.Finish();
ms.Seek(0, SeekOrigin.Begin);
GZipInputStream inStream = new GZipInputStream(ms);
byte[] buf2 = new byte[buf.Length];
int pos = 0;
while (true) {
int numRead = inStream.Read(buf2, pos, 4096);
if (numRead <= 0) {
break;
}
pos += numRead;
}
for (int i = 0; i < buf.Length; ++i) {
Assertion.AssertEquals(buf2[i], buf[i]);
}
}
示例2: BigStream
public void BigStream()
{
window_ = new WindowedStream(0x3ffff);
outStream_ = new GZipOutputStream(window_);
inStream_ = new GZipInputStream(window_);
long target = 0x10000000;
readTarget_ = writeTarget_ = target;
Thread reader = new Thread(Reader);
reader.Name = "Reader";
reader.Start();
Thread writer = new Thread(Writer);
writer.Name = "Writer";
DateTime startTime = DateTime.Now;
writer.Start();
writer.Join();
reader.Join();
DateTime endTime = DateTime.Now;
TimeSpan span = endTime - startTime;
Console.WriteLine("Time {0} processes {1} KB/Sec", span, (target / 1024) / span.TotalSeconds);
}
示例3: CreateTar
/// <summary>
/// Creates a GZipped Tar file from a source directory
/// </summary>
/// <param name="outputTarFilename">Output .tar.gz file</param>
/// <param name="sourceDirectory">Input directory containing files to be added to GZipped tar archive</param>
public static void CreateTar(string outputTarFilename, string sourceDirectory)
{
using (FileStream fs = new FileStream(outputTarFilename, FileMode.Create, FileAccess.Write, FileShare.None))
using (Stream gzipStream = new GZipOutputStream(fs))
using (TarArchive tarArchive = TarArchive.CreateOutputTarArchive(gzipStream))
AddDirectoryFilesToTar(tarArchive, sourceDirectory, true);
}
示例4: CtorErrMsg
public static byte[] CtorErrMsg(string msg, NameValueCollection requestParam)
{
using (MemoryStream ms = new MemoryStream())
{
//包总长度
int len = 0;
long pos = 0;
//包总长度,占位
WriteValue(ms, len);
int actionid = Convert.ToInt32(requestParam["actionid"]);
//StatusCode
WriteValue(ms, 10001);
//msgid
WriteValue(ms, Convert.ToInt32(requestParam["msgid"]));
WriteValue(ms, msg);
WriteValue(ms, actionid);
WriteValue(ms, "st");
//playerdata
WriteValue(ms, 0);
//固定0
WriteValue(ms, 0);
ms.Seek(pos, SeekOrigin.Begin);
WriteValue(ms, (int)ms.Length);
using (var gms = new MemoryStream())
using (var gzs = new GZipOutputStream(gms))
{
gzs.Write(ms.GetBuffer(), 0, (int)ms.Length);
gzs.Flush();
gzs.Close();
return gms.ToArray();
}
}
}
示例5: CreateTarGzFile
public string CreateTarGzFile(List<string> files, string destinationFolder)
{
var fileName = Path.Combine(destinationFolder, DateTime.Now.Ticks.ToString() + ".tar.gz");
Stream outStream = File.Create(fileName);
Stream gzoStream = new GZipOutputStream(outStream);
TarArchive tarArchive = TarArchive.CreateOutputTarArchive(gzoStream);
// Note that the RootPath is currently case sensitive and must be forward slashes e.g. "c:/temp"
// and must not end with a slash, otherwise cuts off first char of filename
// This is scheduled for fix in next release
tarArchive.RootPath = destinationFolder.Replace('\\', '/');
tarArchive.RootPath.TrimEnd("/".ToCharArray());
TarEntry tarEntry = TarEntry.CreateEntryFromFile(destinationFolder);
tarArchive.WriteEntry(tarEntry, false);
foreach (string filename in files)
{
tarEntry = TarEntry.CreateEntryFromFile(filename);
tarArchive.WriteEntry(tarEntry, true);
}
tarArchive.Close();
return fileName;
}
示例6: TestGZip
public void TestGZip()
{
MemoryStream ms = new MemoryStream();
GZipOutputStream outStream = new GZipOutputStream(ms);
byte[] buf = new byte[100000];
System.Random rnd = new Random();
rnd.NextBytes(buf);
outStream.Write(buf, 0, buf.Length);
outStream.Flush();
outStream.Finish();
ms.Seek(0, SeekOrigin.Begin);
GZipInputStream inStream = new GZipInputStream(ms);
byte[] buf2 = new byte[buf.Length];
int currentIndex = 0;
int count = buf2.Length;
while (true) {
int numRead = inStream.Read(buf2, currentIndex, count);
if (numRead <= 0) {
break;
}
currentIndex += numRead;
count -= numRead;
}
Assert.AreEqual(0, count);
for (int i = 0; i < buf.Length; ++i) {
Assert.AreEqual(buf2[i], buf[i]);
}
}
示例7: GetDataSet
public void GetDataSet()
{
SoapContext sc = HttpSoapContext.ResponseContext;
if (null == sc)
{
throw new ApplicationException("Only SOAP requests allowed");
}
SqlConnection conn = new SqlConnection(@"data source=(local)\NetSDK;" +
"initial catalog=Northwind;integrated security=SSPI");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM customers", conn);
DataSet ds = new DataSet("CustomerDS");
da.Fill(ds, "Customers");
// dispose of all objects that are no longer necessary
da.Dispose();
conn.Dispose();
MemoryStream memoryStream = new MemoryStream(1024);
GZipOutputStream gzipStream = new GZipOutputStream(memoryStream);
ds.WriteXml(gzipStream);
gzipStream.Finish();
memoryStream.Seek(0, SeekOrigin.Begin);
DimeAttachment dimeAttachment = new DimeAttachment("application/x-gzip",
TypeFormatEnum.MediaType,
memoryStream);
sc.Attachments.Add(dimeAttachment);
}
示例8: Compress
/// <summary>
/// 压缩文件为gz文件
/// </summary>
/// <param name="sourcefilename">压缩的文件路径</param>
/// <param name="zipfilename">压缩后的gz文件路径</param>
/// <returns></returns>
public static bool Compress(string sourcefilename, string zipfilename)
{
bool blResult;//表示压缩是否成功的返回结果
//为源文件创建读取文件的流实例
FileStream srcFile = File.OpenRead(sourcefilename);
//为压缩文件创建写入文件的流实例
GZipOutputStream zipFile = new GZipOutputStream(File.Open(zipfilename, FileMode.Create));
try
{
byte[] FileData = new byte[srcFile.Length];//创建缓冲数据
srcFile.Read(FileData, 0, (int)srcFile.Length);//读取源文件
zipFile.Write(FileData, 0, FileData.Length);//写入压缩文件
blResult = true;
return blResult;
}
catch
{
blResult = false;
return blResult;
}
finally
{
srcFile.Close();//关闭源文件
zipFile.Close();//关闭压缩文件
}
}
示例9: GZip_Compress_Extract_Test
public void GZip_Compress_Extract_Test() {
var plainStream = PlainText.ToStream();
plainStream.Seek(0, SeekOrigin.Begin);
var plainData = Encoding.UTF8.GetBytes(PlainText);
byte[] compressedData;
byte[] extractedData;
// Compress
using(var compressedStream = new MemoryStream())
using(var gzs = new GZipOutputStream(compressedStream)) {
gzs.SetLevel(5);
gzs.Write(plainData, 0, plainData.Length);
gzs.Finish();
compressedData = compressedStream.ToArray();
}
Assert.IsNotNull(compressedData);
// Extract
using(var compressedStream = new MemoryStream(compressedData)) {
// compressedStream.Seek(0, SeekOrigin.Begin);
using(var gzs = new GZipInputStream(compressedStream))
using(var extractedStream = new MemoryStream()) {
StreamTool.CopyStreamToStream(gzs, extractedStream);
extractedData = extractedStream.ToArray();
}
}
Assert.IsNotNull(extractedData);
string extractedText = Encoding.UTF8.GetString(extractedData).TrimEnd('\0');
Assert.AreEqual(PlainText, extractedText);
}
示例10: Compress
/// <summary>
/// 지정된 데이타를 압축한다.
/// </summary>
/// <param name="input">압축할 Data</param>
/// <returns>압축된 Data</returns>
public override byte[] Compress(byte[] input) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressStartMsg);
// check input data
if(input.IsZeroLength()) {
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.InvalidInputDataMsg);
return CompressorTool.EmptyBytes;
}
byte[] output;
using(var compressedStream = new MemoryStream(input.Length)) {
using(var gzs = new GZipOutputStream(compressedStream)) {
gzs.SetLevel(ZipLevel);
gzs.Write(input, 0, input.Length);
gzs.Finish();
}
output = compressedStream.ToArray();
}
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);
return output;
}
示例11: Write
/// <summary>
/// Write content to the stream and have it compressed using gzip.
/// </summary>
/// <param name="buffer">The bytes to write</param>
/// <param name="offset">The offset into the buffer to start reading bytes</param>
/// <param name="count">The number of bytes to write</param>
public override void Write(byte[] buffer, int offset, int count) {
// GZipOutputStream stream = new GZipOutputStream(BaseStream);
// stream.Write(buffer, offset, count);
// stream.Finish();
if (m_stream == null)
m_stream = new GZipOutputStream(BaseStream);
m_stream.Write(buffer, offset, count);
}
示例12: GZip
public static void GZip(FileInfo fi)
{
byte[] dataBuffer = new byte[4096];
using (Stream s = new GZipOutputStream(File.Create(fi.FullName + ".gz")))
using (FileStream fs = fi.OpenRead())
{
StreamUtils.Copy(fs, s, dataBuffer);
}
}
示例13: compress_gzip
/// <summary>
/// Compresses byte array using gzip
/// Compressed data is returned as a byte array
/// </summary>
/// <param name="inBytes">The bytes to compress</param>
public static byte[] compress_gzip(byte[] inBytes)
{
MemoryStream ContentsGzippedStream = new MemoryStream(); //create the memory stream to hold the compressed file
Stream s = new GZipOutputStream(ContentsGzippedStream); //create the gzip filter
s.Write(inBytes, 0, inBytes.Length); //write the file contents to the filter
s.Flush(); //make sure everythings ready
s.Close(); //close and write the compressed data to the memory stream
return ContentsGzippedStream.ToArray();
}
示例14: CompressBytes
/// <summary>
/// 压缩字节数组
/// 返回:已压缩的字节数组
/// </summary>
/// <param name="bytData">待压缩的字节数组</param>
/// <returns></returns>
public static byte[] CompressBytes(byte[] data)
{
MemoryStream o = new MemoryStream();
Stream s = new ICSharpCode.SharpZipLib.GZip.GZipOutputStream(o);
s.Write(data, 0, data.Length);
s.Close();
o.Flush();
o.Close();
return o.ToArray();
}
示例15: Compress
public static string Compress(string sourceFile){
byte[] dataBuffer = new byte[4096];
string destFile = sourceFile + ".gz";
using (Stream gs = new GZipOutputStream(File.Create(destFile))) {
using (FileStream fs = File.OpenRead(sourceFile)) {
StreamUtils.Copy(fs, gs, dataBuffer);
}
}
return destFile;
}