本文整理汇总了C#中Ionic.Zlib.GZipStream.Read方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.Read方法的具体用法?C# GZipStream.Read怎么用?C# GZipStream.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zlib.GZipStream
的用法示例。
在下文中一共展示了GZipStream.Read方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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();
}
}
}
示例3: 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();
}
示例4: getUnzippedPath
private static string getUnzippedPath(string gzipPath_)
{
var csvPath = gzipPath_.Replace(".gz", string.Empty);
if (File.Exists(csvPath)) return csvPath;
var buffer = new byte[2048];
int n = 1;
try
{
if (!File.Exists(csvPath))
{
using (var input = File.OpenRead(gzipPath_))
{
using (var decompressor = new GZipStream(input, CompressionMode.Decompress, true))
{
using (var output = File.Create(csvPath))
{
do
{
n = decompressor.Read(buffer, 0, buffer.Length);
if (n > 0) output.Write(buffer, 0, n);
}
while (n > 0);
}
}
}
}
}
catch (Exception ex_)
{
Logger.Error(string.Format("Error processing file {0}. error: {1}{2}", gzipPath_, ex_.Message, ex_.StackTrace), typeof(FileHelper));
}
return csvPath;
}
示例5: Decompress
/// <summary>
/// Decompresses a byte array using the specified compression type.
/// </summary>
/// <param name="bytes">The byte array to be decompressed.</param>
/// <param name="type">Type of compression to use.</param>
/// <returns>Decompressed byte array.</returns>
public static byte[] Decompress(this byte[] bytes, CompressionType type)
{
int size = 4096;
byte[] buffer = new byte[size];
using (MemoryStream memory = new MemoryStream())
{
using (MemoryStream memory2 = new MemoryStream(bytes))
switch (type)
{
case CompressionType.Zlib:
using (ZlibStream stream = new ZlibStream(memory2, CompressionMode.Decompress))
{
int count = 0;
while ((count = stream.Read(buffer, 0, size)) > 0)
memory.Write(buffer, 0, count);
}
break;
case CompressionType.GZip:
using (GZipStream stream = new GZipStream(memory2, CompressionMode.Decompress))
{
int count = 0;
while ((count = stream.Read(buffer, 0, size)) > 0)
memory.Write(buffer, 0, count);
}
break;
default:
throw new ArgumentException("Unknown compression type.");
}
return memory.ToArray();
}
}
示例6: Post
private IEnumerator Post(WWW www, Action<string> wwwSuccessCallback, Action<string> wwwErrorCallback)
{
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
wwwErrorCallback(www.error);
}
else
{
#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
if (PlayFabSettings.CompressApiData)
{
try
{
var stream = new MemoryStream(www.bytes);
using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress, false))
{
var buffer = new byte[4096];
using (var output = new MemoryStream())
{
int read;
while ((read = gZipStream.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
output.Seek(0, SeekOrigin.Begin);
var streamReader = new System.IO.StreamReader(output);
var jsonResponse = streamReader.ReadToEnd();
//Debug.Log(jsonResponse);
wwwSuccessCallback(jsonResponse);
}
}
}
catch
{
//if this was not a valid GZip response, then send the message back as text to the call back.
wwwSuccessCallback(www.text);
}
}
else
{
#endif
wwwSuccessCallback(www.text);
#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
}
#endif
}
}
示例7: Gunzip
/// <summary>
/// Gunzips the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns></returns>
/// <remarks></remarks>
public static string Gunzip(this byte[] input) {
var bytes = new List<byte>();
using (var gzStr = new GZipStream(new MemoryStream(input), CompressionMode.Decompress)) {
var bytesRead = new byte[512];
while (true) {
var numRead = gzStr.Read(bytesRead, 0, 512);
if (numRead > 0) {
bytes.AddRange(bytesRead.Take(numRead));
}
else {
break;
}
}
}
return bytes.ToArray().ToUtf8String();
}
示例8: Unzip
protected void Unzip()
{
using (MemoryStream i = new MemoryStream(bytes)) {
// Verify gzip header.
byte[] header = new byte[10];
if (i.Read(header, 0, header.Length) == 10 && header[0] == 0x1F && header[1] == 0x8B && header[2] == 8) {
// Back to start.
i.Seek(0, SeekOrigin.Begin);
using (MemoryStream o = new MemoryStream()) {
using (GZipStream gzip = new GZipStream(i, CompressionMode.Decompress)) {
var buffer = new byte[1024];
do {
int read = gzip.Read(buffer, 0, buffer.Length);
if (read == 0) {
break;
}
o.Write(buffer, 0, read);
} while (true);
}
this.bytes = o.ToArray();
}
}
}
}
示例9: Post
private IEnumerator Post(WWW www, Action<string> wwwSuccessCallback, Action<string> wwwErrorCallback)
{
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
wwwErrorCallback(www.error);
}
else
{
try
{
#if !UNITY_WSA && !UNITY_WP8 && !UNITY_WEBGL
string encoding;
if (www.responseHeaders.TryGetValue("Content-Encoding", out encoding) && encoding.ToLower() == "gzip")
{
var stream = new MemoryStream(www.bytes);
using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress, false))
{
var buffer = new byte[4096];
using (var output = new MemoryStream())
{
int read;
while ((read = gZipStream.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
output.Seek(0, SeekOrigin.Begin);
var streamReader = new System.IO.StreamReader(output);
var jsonResponse = streamReader.ReadToEnd();
//Debug.Log(jsonResponse);
wwwSuccessCallback(jsonResponse);
}
}
}
else
#endif
{
wwwSuccessCallback(www.text);
}
}
catch (Exception e)
{
wwwErrorCallback("Unhandled error in PlayFabWWW: " + e);
}
}
}
示例10: UnpackDirectory
public static void UnpackDirectory(string sourcePath_, string unpackToThisDirectory_, string processedDirectory_, string errorDirectory_, string noMetaDirectory_, bool recurse_, bool processFile_=true)
{
if (!Directory.Exists(sourcePath_))
return;
foreach(var zipPath in Directory.GetFiles(sourcePath_,"*.gz"))
{
var fileName = new FileInfo(zipPath).Name;
var csvFileName = fileName.Replace(".gz", string.Empty);
var unpackPath = string.Format(@"{0}\{1}", unpackToThisDirectory_, csvFileName);
var buffer = new byte[2048];
int n=1;
Logger.Debug(string.Format("Unpacking {0}", new FileInfo(fileName).Name), typeof(FuturesIntradaySaver));
try
{
if (!File.Exists(unpackPath))
{
using (var input = File.OpenRead(zipPath))
{
using (var decompressor = new GZipStream(input, CompressionMode.Decompress, true))
{
using (var output = File.Create(unpackPath))
{
do
{
n = decompressor.Read(buffer, 0, buffer.Length);
if (n > 0) output.Write(buffer, 0, n);
}
while (n > 0);
}
}
}
}
if(processFile_)
processFile(unpackPath, processedDirectory_, errorDirectory_, noMetaDirectory_);
}
catch (Exception ex_)
{
Logger.Error( string.Format("Error processing file {0}. error: {1}{2}", fileName, ex_.Message, ex_.StackTrace),typeof(FuturesIntradaySaver));
string errorPath = string.Format(@"{0}\{1}", errorDirectory_, csvFileName);
if (processFile_ && File.Exists(unpackPath)) File.Move(unpackPath, errorPath);
}
}
if(recurse_)
foreach (var dir in Directory.GetDirectories(sourcePath_))
UnpackDirectory(dir, unpackToThisDirectory_, processedDirectory_, errorDirectory_, noMetaDirectory_, recurse_,
processFile_);
}
示例11: Load
public void Load(Config config, byte[] data)
{
MemoryStream memoryStream = new MemoryStream(data);
BinaryReader br = new BinaryReader(memoryStream);
//Read version info
string version = br.ReadString();
if (version != VERSION_INFO)
return;
//Read compressed bytes
int uncompressedSize = br.ReadInt32();
//Uncompress bytes
byte[] uncompressedBytes = new byte[uncompressedSize];
GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress);
int bytesRead = 0;
while(true)
{
int read = gzipStream.Read(uncompressedBytes, bytesRead, uncompressedSize - bytesRead);
if (read == 0)
break;
bytesRead += read;
}
br = new BinaryReader(new MemoryStream(uncompressedBytes));
//Load world from uncompressed bytes
Load(br, false);
tileManager.Create(config.tileDefinitions, sizeXbits, sizeYbits, sizeZbits);
itemManager.Create(config.itemDefinitions);
avatarManager.Create(config.avatarDefinitions);
sectorManager.Create();
dayCycleManager.Create(config.dayInfo);
tileManager.Load(br);
itemManager.Load(br);
avatarManager.Load(br);
sectorManager.Load(br);
dayCycleManager.Load(br);
gameplay.WorldLoaded();
}
示例12: LoadMultiplayer
public MultiplayerConfig LoadMultiplayer(byte[] data)
{
MemoryStream memoryStream = new MemoryStream(data);
BinaryReader br = new BinaryReader(memoryStream);
//Read compressed bytes
int uncompressedSize = br.ReadInt32();
//Uncompress bytes
byte[] uncompressedBytes = new byte[uncompressedSize];
GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress);
int bytesRead = 0;
while (true)
{
int read = gzipStream.Read(uncompressedBytes, bytesRead, uncompressedSize - bytesRead);
if (read == 0)
break;
bytesRead += read;
}
br = new BinaryReader(new MemoryStream(uncompressedBytes));
//Load world from uncompressed bytes
MultiplayerConfig config = LoadMultiplayer(br);
tileManager.Create(config.tileDefinitions, sizeXbits, sizeYbits, sizeZbits);
itemManager.Create(config.itemDefinitions);
avatarManager.Create(config.avatarDefinitions);
sectorManager.Create();
dayCycleManager.Create(null);
tileManager.Load(br);
itemManager.Load(br);
sectorManager.Load(br);
dayCycleManager.Load(br);
//Player avatar
int playerObjectId = br.ReadInt32();
Player player = (Player) avatarManager.CreateAvatar(avatarManager.GetAvatarDefinitionById("player"), playerObjectId, new Vector3(), false);
player.Load(br);
cwListener.CreateObject(player);
gameplay.WorldLoaded();
return config;
}