本文整理汇总了C#中Ionic.Zlib.GZipStream类的典型用法代码示例。如果您正苦于以下问题:C# GZipStream类的具体用法?C# GZipStream怎么用?C# GZipStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GZipStream类属于Ionic.Zlib命名空间,在下文中一共展示了GZipStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Execute
public override void Execute(object parameter)
{
var saveFile = new SaveFileDialog
{
DefaultExt = ".raven.dump",
Filter = "Raven Dumps|*.raven.dump"
};
var dialogResult = saveFile.ShowDialog() ?? false;
if (!dialogResult)
return;
stream = saveFile.OpenFile();
gZipStream = new GZipStream(stream, CompressionMode.Compress);
streamWriter = new StreamWriter(gZipStream);
jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
output(string.Format("Exporting to {0}", saveFile.SafeFileName));
output("Begin reading indexes");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("Indexes");
jsonWriter.WriteStartArray();
ReadIndexes(0).Catch(exception => Infrastructure.Execute.OnTheUI(() => Finish(exception)));
}
开发者ID:emertechie,项目名称:ravendb,代码行数:30,代码来源:ExportTask.cs
示例2: Compress
static string Compress(string fname, bool forceOverwrite)
{
var outFname = fname + ".gz";
if (File.Exists(outFname))
{
if (forceOverwrite)
File.Delete(outFname);
else
return null;
}
using (var fs = File.OpenRead(fname))
{
using (var output = File.Create(outFname))
{
using (var compressor = new Ionic.Zlib.GZipStream(output, Ionic.Zlib.CompressionMode.Compress))
{
compressor.FileName = fname;
var fi = new FileInfo(fname);
compressor.LastModified = fi.LastWriteTime;
Pump(fs, compressor);
}
}
}
return outFname;
}
开发者ID:nithinphilips,项目名称:SMOz,代码行数:26,代码来源:GZip.cs
示例3: Execute
public override void Execute(object parameter)
{
var saveFile = new SaveFileDialog
{
/*TODO, In Silverlight 5: DefaultFileName = string.Format("Dump of {0}, {1}", ApplicationModel.Database.Value.Name, DateTimeOffset.Now.ToString()), */
DefaultExt = ".raven.dump",
Filter = "Raven Dumps|*.raven.dump",
};
if (saveFile.ShowDialog() != true)
return;
stream = saveFile.OpenFile();
gZipStream = new GZipStream(stream, CompressionMode.Compress);
streamWriter = new StreamWriter(gZipStream);
jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
output(String.Format("Exporting to {0}", saveFile.SafeFileName));
output("Begin reading indexes");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("Indexes");
jsonWriter.WriteStartArray();
ReadIndexes(0).Catch(exception => Infrastructure.Execute.OnTheUI(() => Finish(exception)));
}
开发者ID:NuvemNine,项目名称:ravendb,代码行数:30,代码来源:ExportDatabaseCommand.cs
示例4: Decompress
/// <summary>
/// Decompresses the file at the given path. Returns the path of the
/// decompressed file.
/// </summary>
/// <param name="path">The path to decompress.</param>
/// <returns>The path of the decompressed file.</returns>
public string Decompress(string path)
{
string outputPath = Regex.Replace(path, @"\.gz$", String.Empty, RegexOptions.IgnoreCase);
if (File.Exists(outputPath))
{
File.Delete(outputPath);
}
using (FileStream fs = File.OpenRead(path))
{
using (FileStream output = File.Create(outputPath))
{
using (GZipStream gzip = new GZipStream(fs, CompressionMode.Decompress))
{
byte[] buffer = new byte[4096];
int count = 0;
while (0 < (count = gzip.Read(buffer, 0, buffer.Length)))
{
output.Write(buffer, 0, count);
}
}
}
}
return outputPath;
}
开发者ID:ChadBurggraf,项目名称:sthreeql,代码行数:34,代码来源:GZipCompressor.cs
示例5: Compress
/// <summary>
/// Compresses the file at the given path. Returns the path to the
/// compressed file.
/// </summary>
/// <param name="path">The path to compress.</param>
/// <returns>The path of the compressed file.</returns>
public string Compress(string path)
{
string outputPath = String.Concat(path, ".gz");
if (File.Exists(outputPath))
{
File.Delete(outputPath);
}
using (FileStream fs = File.OpenRead(path))
{
using (FileStream output = File.Create(outputPath))
{
using (GZipStream gzip = new GZipStream(output, CompressionMode.Compress, CompressionLevel.BestCompression))
{
byte[] buffer = new byte[4096];
int count = 0;
while (0 < (count = fs.Read(buffer, 0, buffer.Length)))
{
gzip.Write(buffer, 0, count);
}
}
}
}
return outputPath;
}
开发者ID:ChadBurggraf,项目名称:sthreeql,代码行数:34,代码来源:GZipCompressor.cs
示例6: 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 outStream = new MemoryStream(input.Length)) {
using(var gzip = new GZipStream(outStream, CompressionMode.Compress)) {
gzip.Write(input, 0, input.Length);
}
output = outStream.ToArray();
}
if(IsDebugEnabled)
log.Debug(CompressorTool.SR.CompressResultMsg, input.Length, output.Length, output.Length / (double)input.Length);
return output;
}
开发者ID:debop,项目名称:NFramework,代码行数:31,代码来源:IonicGZipCompressor.cs
示例7: uncompress
public void uncompress(Stream inStream, Stream outStream)
{
GZipStream compressionStream = new GZipStream(inStream, CompressionMode.Decompress, true);
compressionStream.CopyTo(outStream);
}
开发者ID:superkaka,项目名称:mycsharp,代码行数:8,代码来源:GZipCompresser.cs
示例8: Decompress
public byte[] Decompress(Stream inputStream)
{
using (var gzipStream = new GZipStream(inputStream, CompressionMode.Decompress))
using (var outputStream = new MemoryStream())
{
gzipStream.WriteTo(outputStream);
return outputStream.ToArray();
}
}
开发者ID:ryanwentzel,项目名称:DesignPatterns,代码行数:9,代码来源:GZipCompression.cs
示例9: Execute
public override void Execute(object parameter)
{
TaskCheckBox attachmentUI = taskModel.TaskInputs.FirstOrDefault(x => x.Name == "Include Attachments") as TaskCheckBox;
includeAttachments = attachmentUI != null && attachmentUI.Value;
var saveFile = new SaveFileDialog
{
DefaultExt = ".ravendump",
Filter = "Raven Dumps|*.ravendump;*.raven.dump",
};
var name = ApplicationModel.Database.Value.Name;
var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray());
var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture));
try
{
saveFile.DefaultFileName = defaultFileName;
}
catch { }
if (saveFile.ShowDialog() != true)
return;
taskModel.CanExecute.Value = false;
stream = saveFile.OpenFile();
gZipStream = new GZipStream(stream, CompressionMode.Compress);
streamWriter = new StreamWriter(gZipStream);
jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
taskModel.TaskStatus = TaskStatus.Started;
output(String.Format("Exporting to {0}", saveFile.SafeFileName));
jsonWriter.WriteStartObject();
Action finalized = () =>
{
jsonWriter.WriteEndObject();
Infrastructure.Execute.OnTheUI(() => Finish(null));
};
Action readAttachments = () => ReadAttachments(Guid.Empty, 0, callback: finalized);
Action readDocuments = () => ReadDocuments(Guid.Empty, 0, callback: includeAttachments ? readAttachments : finalized);
try
{
ReadIndexes(0, callback: readDocuments);
}
catch (Exception ex)
{
taskModel.ReportError(ex);
Infrastructure.Execute.OnTheUI(() => Finish(ex));
}
}
开发者ID:XpressiveCode,项目名称:ravendb,代码行数:56,代码来源:ExportDatabaseCommand.cs
示例10: compress
public void compress(Stream inStream, Stream outStream)
{
GZipStream compressionStream = new GZipStream(outStream, CompressionMode.Compress, true);
inStream.CopyTo(compressionStream);
compressionStream.Close();
}
开发者ID:superkaka,项目名称:mycsharp,代码行数:10,代码来源:GZipCompresser.cs
示例11: compress
static public byte[] compress(byte[] bytes)
{
var output = new MemoryStream();
var gzipStream = new GZipStream(output, CompressionMode.Compress, true);
gzipStream.Write(bytes, 0, bytes.Length);
gzipStream.Close();
return output.ToArray();
}
开发者ID:superkaka,项目名称:LibForUnity,代码行数:10,代码来源:GZipCompresser.cs
示例12: Compress
public static void Compress(byte[] data, string path)
{
using (GZipStream gzip = new GZipStream(
new FileStream(path, FileMode.Create, FileAccess.Write),
CompressionMode.Compress, CompressionLevel.BestCompression,
false))
{
gzip.Write(data, 0, data.Length);
gzip.Flush();
}
}
开发者ID:Ravenheart,项目名称:driversolutions,代码行数:11,代码来源:Tools.cs
示例13: CompressGzip
public static byte[] CompressGzip(byte[] bytes)
{
using (var ms = new MemoryStream())
{
using (var zip = new GZipStream(ms, CompressionMode.Compress, true))
{
zip.Write(bytes, 0, bytes.Length);
}
return ms.ToArray();
}
}
开发者ID:venusdharan,项目名称:Titanium-Web-Proxy,代码行数:12,代码来源:Compression.cs
示例14: Main
public static int Main(string[] args)
{
var inputFile = args[0];
var targetFolder = args[1];
if (!Directory.Exists(targetFolder))
Directory.CreateDirectory(targetFolder);
var language = _GetLanguage(args);
var type = _GetGramType(args);
var fictionOnly = args.Any(x => x.ToLower() == "fiction");
var versionDate = args.Single(x => x.All(Char.IsNumber));
var includeDependencies = args.Any(x => x.ToLower() == "include0");
var rawHrefs = File.ReadAllLines(inputFile).Select(_GetHref).Where(x => x != null).Select(x => x.ToLower());
var filtered = rawHrefs
.Where(x => x.Contains(_GetNGramTypeForFilter(type).ToLower()))
.Where(x => _FilterByLanguage(x, language))
.Where(x => x.Contains(versionDate)).ToArray();
var connectionString = @"Data Source=.\mssql12;Initial Catalog=NGram;Integrated Security=True";
var oneGramLoader = new OneGramLoader();
foreach (var rawHref in filtered)
{
Console.WriteLine("Downloading href {0}", rawHref);
var req = WebRequest.CreateHttp(rawHref);
var res = req.GetResponse();
using (var resStream = res.GetResponseStream())
{
using (var zipStream = new GZipStream(resStream, CompressionMode.Decompress))
{
using (var sr = new StreamReader(zipStream))
{
oneGramLoader.ProcessOneGram(sr, connectionString);
}
zipStream.Close();
}
resStream.Close();
}
}
Console.WriteLine("Finished - any key");
Console.ReadLine();
return 0;
}
开发者ID:erick-thompson,项目名称:BookNGram,代码行数:49,代码来源:Program.cs
示例15: TwitterLinkBuilder
public string TwitterLinkBuilder(string q)
{
string ret = string.Empty;
JArray output = new JArray();
SortedDictionary<string, string> requestParameters = new SortedDictionary<string, string>();
try
{
var oauth_url = " https://api.twitter.com/1.1/search/tweets.json?q=" + q.Trim() + "&result_type=recent";
var headerFormat = "Bearer {0}";
var authHeader = string.Format(headerFormat, "AAAAAAAAAAAAAAAAAAAAAOZyVwAAAAAAgI0VcykgJ600le2YdR4uhKgjaMs%3D0MYOt4LpwCTAIi46HYWa85ZcJ81qi0D9sh8avr1Zwf7BDzgdHT");
var postBody = requestParameters.ToWebString();
ServicePointManager.Expect100Continue = false;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(oauth_url + "?"
+ requestParameters.ToWebString());
request.Headers.Add("Authorization", authHeader);
request.Method = "GET";
request.Headers.Add("Accept-Encoding", "gzip");
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responseStream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
using (var reader = new StreamReader(responseStream))
{
var objText = reader.ReadToEnd();
output = JArray.Parse(JObject.Parse(objText)["statuses"].ToString());
}
List<string> _lst = new List<string>();
foreach (var item in output)
{
try
{
string _urls = item["entities"]["urls"][0]["expanded_url"].ToString();
if (!string.IsNullOrEmpty(_urls))
_lst.Add(_urls);
}
catch { }
}
ret = new JavaScriptSerializer().Serialize(_lst);
}
catch (Exception ex)
{
logger.Error(ex.Message);
ret = "";
}
return ret;
}
开发者ID:prog-moh,项目名称:socioboard-core,代码行数:49,代码来源:LinkBuilder.asmx.cs
示例16: EnsureGzipFiles
public const int CacheControlOneWeekExpiration = 7 * 24 * 60 * 60; // 1 week
#endregion Fields
#region Methods
/// <summary>
/// Finds all js and css files in a container and creates a gzip compressed
/// copy of the file with ".gzip" appended to the existing blob name
/// </summary>
public static void EnsureGzipFiles(
CloudBlobContainer container,
int cacheControlMaxAgeSeconds)
{
string cacheControlHeader = "public, max-age=" + cacheControlMaxAgeSeconds.ToString();
var blobInfos = container.ListBlobs(
new BlobRequestOptions() { UseFlatBlobListing = true });
Parallel.ForEach(blobInfos, (blobInfo) =>
{
string blobUrl = blobInfo.Uri.ToString();
CloudBlob blob = container.GetBlobReference(blobUrl);
// only create gzip copies for css and js files
string extension = Path.GetExtension(blobInfo.Uri.LocalPath);
if (extension != ".css" && extension != ".js")
return;
// see if the gzip version already exists
string gzipUrl = blobUrl + ".gzip";
CloudBlob gzipBlob = container.GetBlobReference(gzipUrl);
if (gzipBlob.Exists())
return;
// create a gzip version of the file
using (MemoryStream memoryStream = new MemoryStream())
{
// push the original blob into the gzip stream
using (GZipStream gzipStream = new GZipStream(
memoryStream, CompressionMode.Compress, CompressionLevel.BestCompression))
using (BlobStream blobStream = blob.OpenRead())
{
blobStream.CopyTo(gzipStream);
}
// the gzipStream MUST be closed before its safe to read from the memory stream
byte[] compressedBytes = memoryStream.ToArray();
// upload the compressed bytes to the new blob
gzipBlob.UploadByteArray(compressedBytes);
// set the blob headers
gzipBlob.Properties.CacheControl = cacheControlHeader;
gzipBlob.Properties.ContentType = GetContentType(extension);
gzipBlob.Properties.ContentEncoding = "gzip";
gzipBlob.SetProperties();
}
});
}
开发者ID:joelfillmore,项目名称:JFLibrary,代码行数:59,代码来源:CloudBlobUtility.cs
示例17: Decompress
public static void Decompress(byte[] data, string path)
{
byte[] buffer = new byte[BufferSize];
int read;
using (FileStream output = new FileStream(path, FileMode.Create, FileAccess.Write))
using (GZipStream gzip = new GZipStream(new MemoryStream(data), CompressionMode.Decompress, CompressionLevel.BestCompression, false))
{
while ((read = gzip.Read(buffer, 0, BufferSize)) > 0)
{
output.Write(buffer, 0, read);
output.Flush();
}
}
}
开发者ID:Ravenheart,项目名称:driversolutions,代码行数:15,代码来源:Tools.cs
示例18: CreateGZipStream
/// <summary>Creates a GZip stream by the given serialized object.</summary>
private static Stream CreateGZipStream(string serializedObject)
{
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(serializedObject);
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
using (GZipStream gzip = new GZipStream(ms, CompressionMode.Compress, true))
{
gzip.Write(bytes, 0, bytes.Length);
}
// Reset the stream to the beginning. It doesn't work otherwise!
ms.Position = 0;
byte[] compressed = new byte[ms.Length];
ms.Read(compressed, 0, compressed.Length);
return new MemoryStream(compressed);
}
}
开发者ID:Inspirony,项目名称:Emby.Plugins,代码行数:18,代码来源:HttpRequestMessageExtenstions.cs
示例19: Execute
public override void Execute(object parameter)
{
var saveFile = new SaveFileDialog
{
DefaultExt = ".ravendump",
Filter = "Raven Dumps|*.ravendump;*.raven.dump",
};
var name = ApplicationModel.Database.Value.Name;
var normalizedName = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray());
var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture));
try
{
saveFile.DefaultFileName = defaultFileName;
}
catch { }
if (saveFile.ShowDialog() != true)
return;
taskModel.CanExecute.Value = false;
stream = saveFile.OpenFile();
gZipStream = new GZipStream(stream, CompressionMode.Compress);
streamWriter = new StreamWriter(gZipStream);
jsonWriter = new JsonTextWriter(streamWriter)
{
Formatting = Formatting.Indented
};
taskModel.TaskStatus = TaskStatus.Started;
output(String.Format("Exporting to {0}", saveFile.SafeFileName));
output("Begin reading indexes");
jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("Indexes");
jsonWriter.WriteStartArray();
ReadIndexes(0)
.Catch(exception =>
{
taskModel.ReportError(exception);
Infrastructure.Execute.OnTheUI(() => Finish(exception));
});
}
开发者ID:Trebornide,项目名称:ravendb,代码行数:45,代码来源:ExportDatabaseCommand.cs
示例20: uncompress
static public byte[] uncompress(byte[] bytes)
{
byte[] working = new byte[1024 * 20];
var input = new MemoryStream(bytes);
var output = new MemoryStream();
using (Stream decompressor = new GZipStream(input, CompressionMode.Decompress, true))
{
int n;
while ((n = decompressor.Read(working, 0, working.Length)) != 0)
{
output.Write(working, 0, n);
}
}
return output.ToArray();
}
开发者ID:superkaka,项目名称:LibForUnity,代码行数:19,代码来源:GZipCompresser.cs
注:本文中的Ionic.Zlib.GZipStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论