本文整理汇总了C#中System.IO.Compression.GZipStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# GZipStream.ReadByte方法的具体用法?C# GZipStream.ReadByte怎么用?C# GZipStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.GZipStream
的用法示例。
在下文中一共展示了GZipStream.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompress
public byte[] Decompress(byte[] input)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
var output = new List<byte>();
using (var ms = new MemoryStream(input))
{
var gs = new GZipStream(ms, CompressionMode.Decompress);
var readByte = gs.ReadByte();
while (readByte != -1)
{
output.Add((byte)readByte);
readByte = gs.ReadByte();
}
gs.Close();
ms.Close();
}
return output.ToArray();
}
示例2: UncompressFile
static void UncompressFile(string inFilename, string outFilename)
{
FileStream sourceFile = File.OpenRead(inFilename);
FileStream destFile = File.Create(outFilename);
GZipStream compStream = new GZipStream(destFile, CompressionMode.Decompress);
int theByte = compStream.ReadByte();
while (theByte != -1)
{
destFile.WriteByte((byte)theByte);
theByte = compStream.ReadByte();
}
sourceFile.Close();
destFile.Close();
compStream.Close();
}
示例3: Main
static void Main()
{
FileStream source = File.OpenRead(@"D:\archive.zip");
FileStream destination = File.Create(@"D:\text_zip.txt");
GZipStream deCompressor = new GZipStream(source, CompressionMode.Decompress);
int theByte = deCompressor.ReadByte();
while (theByte != -1)
{
destination.WriteByte((byte)theByte);
theByte = deCompressor.ReadByte();
}
deCompressor.Close();
}
示例4: Decompress
public static byte[] Decompress(byte[] input)
{
List<byte> result = new List<byte>();
using (var ms2 = new MemoryStream(input))
{
using (GZipStream zs = new GZipStream(ms2, CompressionMode.Decompress))
{
int read = zs.ReadByte();
while (read != -1)
{
result.Add((byte)read);
read = zs.ReadByte();
}
}
return result.ToArray();
}
}
示例5: Decompress
/// <summary>
/// Decompresses the given byte array
/// </summary>
public byte[] Decompress(byte[] input)
{
using (var output = new MemoryStream(input))
{
using (var zip = new GZipStream(output, CompressionMode.Decompress))
{
var bytes = new List<byte>();
var b = zip.ReadByte();
while (b != -1)
{
bytes.Add((byte)b);
b = zip.ReadByte();
}
return bytes.ToArray();
}
}
}
示例6: Decompress
/// <summary>
/// 解压缩
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static byte[] Decompress(byte[] input)
{
List<byte> output = new List<byte>();
using (MemoryStream ms = new MemoryStream(input))
{
using (GZipStream gs = new GZipStream(ms, CompressionMode.Decompress))
{
int readByte = gs.ReadByte();
while (readByte != -1)
{
output.Add((byte)readByte);
readByte = gs.ReadByte();
}
gs.Close();
}
ms.Close();
}
return output.ToArray();
}
示例7: Assemble
private static void Assemble(List<string> files, string destinationDirectory,string extension)
{
FileStream writer = new FileStream(destinationDirectory + "assembled" + "." + extension,FileMode.Create);
for (int i = 0; i < files.Count; i++)
{
FileStream reader = new FileStream(destinationDirectory + files[i],FileMode.Open,FileAccess.ReadWrite);
GZipStream readerGzip = new GZipStream(reader,CompressionMode.Decompress);
int readBytesVariable = readerGzip.ReadByte();
while (readBytesVariable != -1)
{
writer.WriteByte((byte)readBytesVariable);
readBytesVariable = readerGzip.ReadByte();
}
readerGzip.Dispose();
reader.Dispose();
}
writer.Flush();
writer.Dispose();
}
示例8: GZDecompress
public static byte[] GZDecompress(byte[] source)
{
byte[] buffer2;
if (source == null)
{
throw new ArgumentNullException("source");
}
try
{
using (MemoryStream stream = new MemoryStream())
{
MemoryStream stream2 = new MemoryStream(source);
stream2.Position = 0L;
using (GZipStream stream3 = new GZipStream(stream2, CompressionMode.Decompress, true))
{
bool flag2;
byte[] buffer = new byte[0x1000];
bool flag = false;
long num2 = 0L;
int num3 = 0;
goto Label_0096;
Label_0052:
num3 = stream3.ReadByte();
if (num3 != -1)
{
if (!flag)
{
flag = true;
}
num2 += 1L;
stream.WriteByte((byte) num3);
}
else if (flag)
{
goto Label_009B;
}
Label_0096:
flag2 = true;
goto Label_0052;
Label_009B:
stream3.Close();
Console.WriteLine("Original size: {0}, DeCompressed size: {1}", source.Length, stream.Length);
}
buffer2 = stream.ToArray();
}
}
catch (Exception exception)
{
LoggingService.Error("GZip解压缩时出错:", exception);
buffer2 = source;
}
return buffer2;
}
示例9: Load
public override Map Load( string fileName ) {
if ( fileName == null ) throw new ArgumentNullException( "fileName" );
using ( FileStream mapStream = File.OpenRead( fileName ) ) {
using ( var gs = new GZipStream( mapStream, CompressionMode.Decompress ) ) {
Map map = LoadHeaderInternal(gs);
map.Blocks = new byte[map.Volume];
int i = 0, b, s;
while ((b = gs.ReadByte()) != -1)
{
s = gs.ReadByte();
short val = BitConverter.ToInt16( new[] { ( byte ) b, ( byte ) s }, 0 );
if (val <= 65)
{
map.Blocks[i] = ( byte ) val;
}
else
{
map.Blocks[i] = Mapping[val];
}
}
// Read in the map data
map.Blocks = new byte[map.Volume];
BufferUtil.ReadAll(gs, map.Blocks);
map.ConvertBlockTypes(Mapping);
return map;
}
}
}
示例10: Decompress
public byte[] Decompress(byte[] fileBytes)
{
byte[] bytes;
using (MemoryStream fileStream = new MemoryStream(fileBytes)) {
using (GZipStream zipStream = new GZipStream(fileStream, CompressionMode.Decompress)) {
using (MemoryStream decompressedStream = new MemoryStream()) {
int value;
while ((value = zipStream.ReadByte()) != -1) {
decompressedStream.WriteByte((byte) value);
}
zipStream.Close();
bytes = decompressedStream.ToArray();
}
}
}
return bytes;
}
示例11: Load
public bool Load(string filename)
{
try
{
this.filename = filename;
GZipStream gzin = new GZipStream(new FileStream("maps/" + filename, FileMode.Open), CompressionMode.Decompress);
byte[] magicnumbytes = new byte[4];
gzin.Read(magicnumbytes, 0, 4);
if (!(BitConverter.ToUInt32(magicnumbytes, 0) == 0xebabefac))
{
Program.server.logger.log("Wrong magic number in level file: " + BitConverter.ToUInt32(magicnumbytes, 0), Logger.LogType.Error);
return false;
}
byte[] leveldimensions = new byte[6];
gzin.Read(leveldimensions, 0, 6);
this.width = BitConverter.ToInt16(leveldimensions, 0);
this.height = BitConverter.ToInt16(leveldimensions, 2);
this.depth = BitConverter.ToInt16(leveldimensions, 4);
byte[] spawnpoint = new byte[6];
gzin.Read(spawnpoint, 0, 6);
this.spawnx = BitConverter.ToInt16(spawnpoint, 0);
this.spawny = BitConverter.ToInt16(spawnpoint, 2);
this.spawnz = BitConverter.ToInt16(spawnpoint, 4);
this.srotx = (byte)gzin.ReadByte();
this.sroty = (byte)gzin.ReadByte();
this.blocks = new byte[this.width * this.height * this.depth];
gzin.Read(blocks, 0, this.width * this.height * this.depth);
//gzin.BaseStream.Close();
gzin.Close();
this.name = filename.Substring(0, filename.IndexOf(".umw"));
this.messageBlocks = new Dictionary<int, string>();
this.teleportBlocks = new Dictionary<int, int>();
if (File.Exists("maps/" + this.name + ".mb"))
{
StreamReader mBlocksIn = new StreamReader(File.Open("maps/" + this.name + ".mb", FileMode.Open));
string line = "";
while (!mBlocksIn.EndOfStream)
{
line = mBlocksIn.ReadLine();
if (!line.Contains(" ")) break;
int index = Int32.Parse(line.Substring(0, line.IndexOf(" ")));
string msg = line.Substring(line.IndexOf(" ") + 1);
this.messageBlocks.Add(index, msg);
}
mBlocksIn.Close();
}
if (File.Exists("maps/" + this.name + ".tb"))
{
StreamReader tBlocksIn = new StreamReader(File.Open("maps/" + this.name + ".tb", FileMode.Open));
string line = "";
while (!tBlocksIn.EndOfStream)
{
line = tBlocksIn.ReadLine();
if (!line.Contains(" ")) break;
int index = Int32.Parse(line.Substring(0, line.IndexOf(" ")));
int value = Int32.Parse(line.Substring(line.IndexOf(" ") + 1));
this.teleportBlocks.Add(index, value);
}
tBlocksIn.Close();
}
Program.server.logger.log("Loaded world from " + filename);
return true;
}
catch (Exception e)
{
Program.server.logger.log("Error occurred while loading map", Logger.LogType.Error);
Program.server.logger.log(e);
return false;
}
}
示例12: IOLoop
void IOLoop()
{
byte[] loginPacket = CreateLoginPacket(migratedUsername ?? _username, _ver);
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try {
if(EndPoint.Port > IPEndPoint.MaxPort || EndPoint.Port < IPEndPoint.MinPort) throw new SocketException(-1);
//Do not continue if the user attempts to connect on a port larger than possible.
ServerSocket.Connect(EndPoint);
ServerSocket.Send(loginPacket);
} catch( SocketException ex ) {
Log( LogType.Error, HandleSocketError( ex.ErrorCode ), ex.ToString() );
return;
}
BinaryReader reader = new BinaryReader(new NetworkStream(ServerSocket));
while (true)
{
try
{
byte OpCode = reader.ReadByte();
PacketEventArgs opcodeEvent = new PacketEventArgs((ServerPackets)OpCode);
Events.RaisePacketReceived(opcodeEvent);
switch ((ServerPackets)OpCode)
{
case ServerPackets.ServerIdentification://0x00
{
ProtocolVersion = reader.ReadByte(); // Protocol version should be seven.
string Name = Encoding.ASCII.GetString(reader.ReadBytes(64)).Trim();
string MOTD = Encoding.ASCII.GetString(reader.ReadBytes(64)).Trim();
if(!serverLoaded)
{
ServerName = Name;
ServerMOTD = MOTD;
serverLoaded = true;
}
UserType = reader.ReadByte();//Get the type. 0x64 = Op, 0x00 = Normal user.
}
break;
case ServerPackets.Ping://0x01
break; // Server only requires we read the packet ID.
case ServerPackets.LevelInitialize://0x02
Players.Clear();
if(_savemap) mapStream = new MemoryStream();
CanReconnectAfterKick = true;
break;
case ServerPackets.LevelDataChunk://0x03
{
int chunkLength = IPAddress.HostToNetworkOrder(reader.ReadInt16()); // Length of non padded data.
byte[] chunkData = reader.ReadBytes(1024); // May be padded with extra data.
byte progress = reader.ReadByte();
if(_savemap) {
mapStream.Write( chunkData, 0, chunkLength );
}
MapProgressEventArgs e = new MapProgressEventArgs(progress);
Events.RaiseMapProgress(e);
}
break;
case ServerPackets.LevelFinalize://0x04:
{
MapSizeX = IPAddress.HostToNetworkOrder(reader.ReadInt16());
MapSizeZ = IPAddress.HostToNetworkOrder(reader.ReadInt16());
MapSizeY = IPAddress.HostToNetworkOrder(reader.ReadInt16());
Connected = true; //At this state, we've loaded the map and we're ready to send chat etc.
if(_savemap) {
Log( LogType.BotActivity, "Beginning to save map.." );
mapStream.Seek(0, SeekOrigin.Begin);
Map map = new Map(MapSizeX, MapSizeY, MapSizeZ);
using (GZipStream decompressed = new GZipStream( mapStream,CompressionMode.Decompress ) ) {
decompressed.Read( new byte[4], 0, 4 ); //Ignore size of stream.
int sizeX = MapSizeX, sizeY = MapSizeY, sizeZ = MapSizeZ;
for( int z = 0; z < sizeZ; z++ ) {
for( int y = 0; y < sizeY; y++ ) {
for( int x = 0; x < sizeX; x++ ) {
byte next = (byte)decompressed.ReadByte();
map.SetBlock( x, y, z, next );
}
}
}
}
mapStream.Dispose();
map.Save("map_" + DateTime.Now.ToString("ddHHmmssfffffff")); //Formatting for DateTime.
map.Dispose();
Log( LogType.BotActivity, "Saved map" );
}
MapLoadedEventArgs e = new MapLoadedEventArgs();
Events.RaiseMapLoaded(e);
}
break;
case ServerPackets.SetBlock://0x06:
{
int blockX = IPAddress.HostToNetworkOrder(reader.ReadInt16());
int blockZ = IPAddress.HostToNetworkOrder(reader.ReadInt16());
int blockY = IPAddress.HostToNetworkOrder(reader.ReadInt16());
//.........这里部分代码省略.........
示例13: Add
/// <summary>
/// Adds the xml files provided to the provider.
/// </summary>
/// <param name="provider">The provider to be modified.</param>
/// <param name="files">List of files to be processed.</param>
public static void Add(Provider provider, IList<string> files)
{
var streams = new List<Stream>();
try
{
foreach (string file in files)
{
var fileInfo = new FileInfo(file);
if (fileInfo.Exists)
{
if (Detection.Constants.CompressedFileExtensions.Contains(fileInfo.Extension))
{
// This is a compressed file. It needs to be copied to a memory stream
// to enable multiple passed of the data.
var ms = new MemoryStream();
var temp = new GZipStream(
new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read),
CompressionMode.Decompress);
// Copy the data to the memory stream.
int value = temp.ReadByte();
while (value > 0)
{
ms.WriteByte((byte)value);
value = temp.ReadByte();
}
streams.Add(ms);
}
else
streams.Add(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read));
}
}
Add(provider, streams);
}
finally
{
foreach (var stream in streams)
stream.Dispose();
}
}
示例14: LoadDictionaryFromHSpellFolder
public static DictRadix<MorphData> LoadDictionaryFromHSpellFolder(string path, bool bLoadMorphData)
{
if (path[path.Length - 1] != Path.DirectorySeparatorChar)
path += Path.DirectorySeparatorChar;
if (bLoadMorphData)
{
// Load the count of morphological data slots required
string sizesFile = File.ReadAllText(path + HSpell.Constants.SizesFile);
int lookupLen = sizesFile.IndexOf(' ', sizesFile.IndexOf('\n'));
lookupLen = Convert.ToInt32(sizesFile.Substring(lookupLen + 1));
string[] lookup = new string[lookupLen + 1];
using (GZipStream fdict = new GZipStream(File.OpenRead(path + HSpell.Constants.DictionaryFile), CompressionMode.Decompress))
{
char[] sbuf = new char[HSpell.Constants.MaxWordLength];
int c = 0, n, slen = 0, i = 0;
while ((c = fdict.ReadByte()) > -1)
{
if (c >= '0' && c <= '9') // No conversion required for chars < 0xBE
{
/* new word - finalize and save old word */
lookup[i++] = new string(sbuf, 0, slen);
/* and read how much to go back */
n = 0;
do
{
/* base 10... */
n *= 10;
n += (c - '0');
} while ((c = fdict.ReadByte()) > -1 && c >= '0' && c <= '9');
slen -= n;
}
sbuf[slen++] = ISO8859_To_Unicode(c);
}
}
using (MorphDataLoader dataLoader = new MorphDataLoader(path + HSpell.Constants.DescFile,
path + HSpell.Constants.StemsFile))
{
using (GZipStream fprefixes = new GZipStream(File.OpenRead(path + HSpell.Constants.PrefixesFile), CompressionMode.Decompress))
{
DictRadix<MorphData> ret = new DictRadix<MorphData>();
for (int i = 0; lookup[i] != null; i++)
{
MorphData data = new MorphData();
data.Prefixes = Convert.ToByte(fprefixes.ReadByte()); // Read prefix hint byte
data.DescFlags = dataLoader.ReadDescFile();
List<int> stemReferences = dataLoader.ReadStemFile();
data.Lemmas = new string[stemReferences.Count];
int stemPosition = 0;
foreach (int r in stemReferences)
{
// This is a bypass for the psuedo-stem "שונות", as defined by hspell
// TODO: Try looking into changing this in hspell itself
if (lookup[r].Equals("שונות") && !lookup[r].Equals(lookup[i]))
{
data.Lemmas[stemPosition++] = null;
}
else
{
data.Lemmas[stemPosition++] = lookup[r];
}
}
ret.AddNode(lookup[i], data);
}
return ret;
}
}
}
else // Use optimized version for loading HSpell's dictionary files
{
using (GZipStream fdict = new GZipStream(File.OpenRead(path + HSpell.Constants.DictionaryFile), CompressionMode.Decompress))
{
using (GZipStream fprefixes = new GZipStream(File.OpenRead(path + HSpell.Constants.PrefixesFile), CompressionMode.Decompress))
{
DictRadix<MorphData> ret = new DictRadix<MorphData>();
char[] sbuf = new char[HSpell.Constants.MaxWordLength];
int c = 0, n, slen = 0;
while ((c = fdict.ReadByte()) > -1)
{
if (c >= '0' && c <= '9') // No conversion required for chars < 0xBE
{
/* new word - finalize old word first (set value) */
sbuf[slen] = '\0';
// TODO: Avoid creating new MorphData object, and enhance DictRadix to store
// the prefixes mask in the node itself
MorphData data = new MorphData();
data.Prefixes = Convert.ToByte(fprefixes.ReadByte()); // Read prefix hint byte
ret.AddNode(sbuf, data);
/* and read how much to go back */
n = 0;
do
//.........这里部分代码省略.........
示例15: TestBasicRequestHandling
//.........这里部分代码省略.........
testRequest("GET test #7", store, "GET /64kfile HTTP/1.1\r\nHost: localhost\r\nRange: bytes=23459-38274\r\n\r\n", (headers, content) =>
{
Assert.AreEqual("HTTP/1.1 206 Partial Content", headers[0]);
Assert.IsTrue(headers.Contains("Accept-Ranges: bytes"));
Assert.IsTrue(headers.Contains("Content-Range: bytes 23459-38274/65536"));
Assert.IsTrue(headers.Contains("Content-Type: application/octet-stream"));
Assert.IsTrue(headers.Contains("Content-Length: 14816"));
for (int i = 0; i < content.Length; i++)
Assert.AreEqual((byte) ((163 + i) % 256), content[i]);
});
testRequest("GET test #8", store, "GET /64kfile HTTP/1.1\r\nHost: localhost\r\nRange: bytes=65-65,67-67\r\n\r\n", (headers, content) =>
{
Assert.AreEqual("HTTP/1.1 206 Partial Content", headers[0]);
Assert.IsTrue(headers.Contains("Accept-Ranges: bytes"));
Assert.IsTrue(headers.Any(x => Regex.IsMatch(x, @"^Content-Type: multipart/byteranges; boundary=[0-9A-F]+$")));
string boundary = headers.First(x => Regex.IsMatch(x, @"^Content-Type: multipart/byteranges; boundary=[0-9A-F]+$")).Substring(45);
Assert.IsTrue(headers.Contains("Content-Length: 284"));
byte[] expectedContent = ("--" + boundary + "\r\nContent-Range: bytes 65-65/65536\r\n\r\nA\r\n--" + boundary + "\r\nContent-Range: bytes 67-67/65536\r\n\r\nC\r\n--" + boundary + "--\r\n").ToUtf8();
Assert.AreEqual(expectedContent.Length, content.Length);
for (int i = 0; i < expectedContent.Length; i++)
Assert.AreEqual(expectedContent[i], content[i]);
});
testRequest("GET test #9", store, "GET /64kfile HTTP/1.1\r\nHost: localhost\r\nAccept-Encoding: gzip\r\n\r\n", (headers, content) =>
{
Assert.AreEqual("HTTP/1.1 200 OK", headers[0]);
Assert.IsTrue(headers.Contains("Accept-Ranges: bytes"));
Assert.IsTrue(headers.Contains("Content-Type: application/octet-stream"));
Assert.IsTrue(headers.Contains("Content-Encoding: gzip"));
Assert.IsTrue(headers.Any(h => h.StartsWith("Content-Length")));
GZipStream gz = new GZipStream(new MemoryStream(content), CompressionMode.Decompress);
for (int i = 0; i < 65536; i++)
Assert.AreEqual(i % 256, gz.ReadByte());
Assert.AreEqual(-1, gz.ReadByte());
});
testRequest("GET test #10", store, "GET /dynamic HTTP/1.1\r\n\r\n", (headers, content) => Assert.AreEqual("HTTP/1.1 400 Bad Request", headers[0]));
testRequest("GET test #11", store, "INVALID /request HTTP/1.1\r\n\r\n", (headers, content) => Assert.AreEqual("HTTP/1.1 400 Bad Request", headers[0]));
testRequest("GET test #12", store, "GET HTTP/1.1\r\n\r\n", (headers, content) => Assert.AreEqual("HTTP/1.1 400 Bad Request", headers[0]));
testRequest("GET test #13", store, "!\r\n\r\n", (headers, content) => Assert.AreEqual("HTTP/1.1 400 Bad Request", headers[0]));
}
finally
{
instance.StopListening();
}
foreach (var storeFileUploadInFileAtSize in new[] { 5, 1024 })
{
instance = new HttpServer(ProgramServersTests.Port, new HttpServerOptions { StoreFileUploadInFileAtSize = storeFileUploadInFileAtSize })
{
Handler = new UrlResolver(
new UrlMapping(handlerStatic, path: "/static"),
new UrlMapping(handlerDynamic, path: "/dynamic")
).Handle
};
try
{
instance.StartListening();
testRequest("POST test #1", storeFileUploadInFileAtSize, "POST /static HTTP/1.1\r\nHost: localhost\r\nContent-Length: 48\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nx=y&z=%20&zig=%3D%3d&a[]=1&a%5B%5D=2&%61%5b%5d=3", (headers, content) =>
{
Assert.AreEqual("HTTP/1.1 200 OK", headers[0]);
Assert.IsTrue(headers.Contains("Content-Type: text/plain; charset=utf-8"));
Assert.IsTrue(headers.Contains("Content-Length: 66"));
Assert.AreEqual("\nPOST:\nx => [\"y\"]\nz => [\" \"]\nzig => [\"==\"]\na[] => [\"1\", \"2\", \"3\"]\n", content.FromUtf8());