本文整理汇总了C#中GZipStream.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.CopyTo方法的具体用法?C# GZipStream.CopyTo怎么用?C# GZipStream.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GZipStream
的用法示例。
在下文中一共展示了GZipStream.CopyTo方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompress
public static byte[] Decompress(this Byte[] bytes)
{
using (MemoryStream tempMs = new MemoryStream()) {
using (MemoryStream ms = new MemoryStream(bytes)) {
GZipStream Decompress = new GZipStream(ms, CompressionMode.Decompress);
Decompress.CopyTo(tempMs);
Decompress.Close();
return tempMs.ToArray();
}
}
}
示例2: MutateIncoming
public void MutateIncoming(TransportMessage transportMessage)
{
if (!transportMessage.Headers.ContainsKey("IWasCompressed"))
{
return;
}
using (GZipStream bigStream = new GZipStream(new MemoryStream(transportMessage.Body), CompressionMode.Decompress))
{
MemoryStream bigStreamOut = new MemoryStream();
bigStream.CopyTo(bigStreamOut);
transportMessage.Body = bigStreamOut.ToArray();
}
}
示例3: MutateIncoming
public Task MutateIncoming(MutateIncomingTransportMessageContext context)
{
if (!context.Headers.ContainsKey("IWasCompressed"))
{
return Task.FromResult(0);
}
using (GZipStream bigStream = new GZipStream(new MemoryStream(context.Body), CompressionMode.Decompress))
{
MemoryStream bigStreamOut = new MemoryStream();
bigStream.CopyTo(bigStreamOut);
context.Body = bigStreamOut.ToArray();
}
return Task.FromResult(0);
}
示例4: ExtractGZip
/// <summary>
/// A FileInfo extension method that extracts the g zip.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <example>
/// <code>
/// using System;
/// using System.IO;
/// using Microsoft.VisualStudio.TestTools.UnitTesting;
/// using Z.ExtensionMethods;
///
/// namespace ExtensionMethods.Examples
/// {
/// [TestClass]
/// public class System_IO_FileInfo_ExtractGZip
/// {
/// [TestMethod]
/// public void ExtractGZip()
/// {
/// // Type
/// var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ExtractGZip.txt"));
/// var output = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ExtractGZip.gz"));
/// var outputExtract = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ExtractGZip_Example.txt"));
///
/// // Intialization
/// using (FileStream stream = @this.Create())
/// {
/// }
///
/// // Examples
/// @this.CreateGZip(output);
/// output.ExtractGZip(outputExtract);
///
/// // Unit Test
/// Assert.IsTrue(outputExtract.Exists);
/// }
/// }
/// }
/// </code>
/// </example>
public static void ExtractGZip(this FileInfo @this)
{
using (FileStream originalFileStream = @this.OpenRead())
{
string newFileName = Path.GetFileNameWithoutExtension(@this.FullName);
using (FileStream decompressedFileStream = File.Create(newFileName))
{
using (var decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
{
decompressionStream.CopyTo(decompressedFileStream);
}
}
}
}
示例5: DecompressFile
public static bool DecompressFile(string pathToCompressedFile, string pathToDecompressedFile)
{
if (File.Exists(pathToCompressedFile))
{
using (FileStream inFile = File.Open(pathToCompressedFile, FileMode.Open))
{
using (FileStream outFile = File.Create(pathToDecompressedFile))
{
using (GZipStream Decompress = new GZipStream(inFile,
CompressionMode.Decompress))
{
Decompress.CopyTo(outFile);
}
}
}
}
else
{
return false;
}
return true;
}
示例6: GiaiNen
//
// Giai nen file TUDIEN duoc nen o dang .gz
//
public void GiaiNen(string DAUVAO, string DAURA)
{
using (FileStream streamMoFileGiaiNen = new FileStream(DAUVAO, FileMode.Open))
{
using (FileStream streamSauKhiGiaiNen = File.Create(DAURA))
{
using (GZipStream gzreader = new GZipStream(streamMoFileGiaiNen, CompressionMode.Decompress))
{
gzreader.CopyTo(streamSauKhiGiaiNen);
}
}
}
}
示例7: ServiceRpc
/// <summary>
/// "transfer-encoding:chunked is not supported.
/// Workaround: Set 'git config --add --global http.postBuffer 10485760'
/// </summary>
/// <param name="serviceName"></param>
private void ServiceRpc(string serviceName)
{
context.Response.ContentType = string.Format("application/x-git-{0}-result", serviceName);
var fin = Path.GetTempFileName();
var fout = Path.GetTempFileName();
using (var file = File.Create(fin))
{
var encoding = context.Request.Headers["Content-Encoding"];
if (string.IsNullOrEmpty(encoding))
encoding = context.Request.ContentEncoding.EncodingName;
if (encoding.Equals("gzip"))
{
using (GZipStream decomp = new GZipStream(context.Request.InputStream, CompressionMode.Decompress))
{
decomp.CopyTo(file);
}
}
else
{
context.Request.InputStream.CopyTo(file);
}
}
Git.RunGitCmd(string.Format("{0} --stateless-rpc \"{1}\" < \"{2}\" > \"{3}\"", serviceName, gitWorkingDir, fin, fout));
context.Response.WriteFile(fout);
context.Response.End();
File.Delete(fin);
File.Delete(fout);
}
示例8: DownloadSub
protected void DownloadSub(object sender, EventArgs e)
{
var tempdir = Environment.GetEnvironmentVariable ("TEMP", EnvironmentVariableTarget.Machine);
if (string.IsNullOrEmpty (tempdir))
tempdir = "/tmp";
var selectednode = (MovieTreeNode)MovieNodeView.NodeSelection.SelectedNode;
if (selectednode == null)
return;
string movietitle = System.IO.Path.GetFileNameWithoutExtension (_fname);
var client = new WebClient ();
string filename = tempdir + "/tmp_" + movietitle + ".gz";
client.DownloadFile (selectednode.DownloadLink, filename);
var fileToDecompress = new FileInfo (filename);
string currentFileName = fileToDecompress.FullName;
string newFileName = currentFileName.Remove (currentFileName.Length - fileToDecompress.Extension.Length);
using (FileStream originalFileStream = fileToDecompress.OpenRead()) {
using (FileStream decompressedFileStream = File.Create(newFileName)) {
using (var decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) {
decompressionStream.CopyTo (decompressedFileStream);
}
}
}
fileToDecompress.Delete ();
string origlocation = System.IO.Path.GetDirectoryName (_fname);
string newfile = origlocation + "/" + movietitle + "." + selectednode.SubFormat;
if (File.Exists (newfile)) {
File.Delete (newfile);
} //TODO: ask for overwrite?
File.Move (newFileName, newfile);
statusbar1.Push (3, "Downloaded " + newfile + ".");
Downloadbutton.Sensitive = false;
}