本文整理汇总了C#中Ionic.Zlib.GZipStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.Close方法的具体用法?C# GZipStream.Close怎么用?C# GZipStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zlib.GZipStream
的用法示例。
在下文中一共展示了GZipStream.Close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: compress
public void compress(Stream inStream, Stream outStream)
{
GZipStream compressionStream = new GZipStream(outStream, CompressionMode.Compress, true);
inStream.CopyTo(compressionStream);
compressionStream.Close();
}
示例3: Write
public void Write()
{
TAG_Compound data;
using (FileStream level = new FileStream(LevelDatPath, FileMode.Open))
{
using (GZipStream decompress = new GZipStream(level, CompressionMode.Decompress))
{
MemoryStream mem = new MemoryStream();
decompress.CopyTo(mem);
mem.Seek(0, SeekOrigin.Begin);
data = new TAG_Compound(mem);
}
}
((TAG_Long)data["Data"]["RandomSeed"]).Payload = Seed;
using (FileStream level = new FileStream(LevelDatPath, FileMode.Truncate))
{
MemoryStream mem = new MemoryStream();
GZipStream compress = new GZipStream(mem, CompressionMode.Compress);
data.Write(compress);
compress.Close();
byte[] buffer = mem.ToArray();
level.Write(buffer, 0, buffer.Length);
}
}
示例4: Zlib_DisposedException_GZipStream
public void Zlib_DisposedException_GZipStream()
{
string TextToCompress = IhaveaDream;
MemoryStream ms1= new MemoryStream();
Stream compressor= new GZipStream(ms1, CompressionMode.Compress, false);
TestContext.WriteLine("Text to compress is {0} bytes: '{1}'",
TextToCompress.Length, TextToCompress);
TestContext.WriteLine("using compressor: {0}", compressor.GetType().FullName);
StreamWriter sw = new StreamWriter(compressor, Encoding.ASCII);
sw.Write(TextToCompress);
sw.Close(); // implicitly closes compressor
sw.Close(); // implicitly closes compressor, again
compressor.Close(); // explicitly closes compressor
var a = ms1.ToArray();
TestContext.WriteLine("Compressed stream is {0} bytes long", a.Length);
var ms2 = new MemoryStream(a);
Stream decompressor = new GZipStream(ms2, CompressionMode.Decompress, false);
TestContext.WriteLine("using decompressor: {0}", decompressor.GetType().FullName);
var sr = new StreamReader(decompressor, Encoding.ASCII);
string DecompressedText = sr.ReadToEnd();
sr.Close();
TestContext.WriteLine("decompressor.CanRead = {0}",decompressor.CanRead);
TestContext.WriteLine("Read {0} characters: '{1}'", DecompressedText.Length, DecompressedText);
TestContext.WriteLine("\n");
Assert.AreEqual<String>(TextToCompress, DecompressedText);
}
示例5: SaveMultiplayer
public byte[] SaveMultiplayer(Player player)
{
//Save world to memory
MemoryStream bytesStream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(bytesStream);
//Basic world info
SaveMultiplayer(bw);
//Managers
tileManager.Save(bw);
itemManager.Save(bw);
sectorManager.Save(bw);
dayCycleManager.Save(bw);
//Player avatar
bw.Write(player.objectId);
player.Save(bw);
bw.Flush();
byte[] bytes = bytesStream.ToArray();
//Write header
MemoryStream bytesStreamFinal = new MemoryStream();
BinaryWriter bwFinal = new BinaryWriter(bytesStreamFinal);
bwFinal.Write(bytes.Length);
bwFinal.Flush();
//Compress and write world
GZipStream gzipStream = new GZipStream(bytesStreamFinal, CompressionMode.Compress, CompressionLevel.BestSpeed, true);
gzipStream.Write(bytes, 0, bytes.Length);
gzipStream.Close();
return bytesStreamFinal.ToArray();
}
示例6: Save
public byte[] Save()
{
//Save world to memory
MemoryStream bytesStream = new MemoryStream();
BinaryWriter bw = new BinaryWriter(bytesStream);
Save(bw, false);
tileManager.Save(bw);
itemManager.Save(bw);
avatarManager.Save(bw);
sectorManager.Save(bw);
dayCycleManager.Save(bw);
bw.Flush();
byte[] bytes = bytesStream.ToArray();
//Write header
MemoryStream bytesStreamFinal = new MemoryStream();
BinaryWriter bwFinal = new BinaryWriter(bytesStreamFinal);
bwFinal.Write(VERSION_INFO);
bwFinal.Write(bytes.Length);
bwFinal.Flush();
//Compress and write world
GZipStream gzipStream = new GZipStream(bytesStreamFinal, CompressionMode.Compress, CompressionLevel.BestSpeed, true);
gzipStream.Write(bytes, 0, bytes.Length);
gzipStream.Close();
return bytesStreamFinal.ToArray();
}
示例7: 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;
}