C# MemoryStream.ReadByte的代码示例
通过代码示例来学习C# MemoryStream.ReadByte方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
MemoryStream.ReadByte是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的MemoryStream.ReadByte() 已经帮大家高亮显示了,大家可以重点学习MemoryStream.ReadByte() 方法的写法,从而快速掌握该方法的应用。
MemoryStream.ReadByte的代码示例1 - InflateZLIB()
using System.IO; public static byte[] InflateZLIB(byte[] i) { var stream = new MemoryStream(); var ms = new MemoryStream(i); ms.ReadByte(); ms.ReadByte(); var zlibStream = new DeflateStream(ms, CompressionMode.Decompress); byte[] buffer = new byte[4095]; while (true) { int size = zlibStream.Read(buffer, 0, buffer.Length); if (size > 0) stream.Write(buffer, 0, buffer.Length); else break; } zlibStream.Close(); return stream.ToArray(); }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:20,代码来源:FileReader.cs
在InflateZLIB()方法中,MemoryStream的代码示例类中的ReadByte的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.ReadByte的代码示例2 - Decompress()
using System.IO; public Stream Decompress(Stream stream) { using (var reader = new FileReader(stream, true)) { reader.SeekBegin(12); byte type = reader.ReadByte(); if (type == 0x11) { uint decomp_size = reader.ReadUInt32(); var sub = new SubStream(stream, 16); return new MemoryStream(LZ77_WII.Decompress11(sub.ToArray(), (int)decomp_size)); } else { return new MemoryStream(); } } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:21,代码来源:LZ77.cs
在Decompress()方法中,MemoryStream的代码示例类中的ReadByte的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.ReadByte的代码示例3 - Decompress10LZ()
using System.IO; //Ported from //https://github.com/Barubary/dsdecmp/blob/master/Java/JavaDSDecmp.java#L27 //Rewrote to C# public static byte[] Decompress10LZ(byte[] in_data, int decomp_size) { byte[] out_data = new byte[decomp_size]; int curr_size = 0, flags, disp, n, b, cdest; bool flag; var reader = new FileReader(new MemoryStream(in_data), true); while (curr_size < decomp_size) { try { flags = reader.ReadByte(); } catch (EndOfStreamException ex) { throw ex; } for (int i = 0; i < 8; i++) { flag = (flags & (0x80 >> i)) > 0; if (flag) { disp = 0; try { b = reader.ReadByte(); } catch (EndOfStreamException ex) { throw new InvalidDataException("Incomplete data", ex); } n = b >> 4; disp = (b & 0x0F) << 8; try { disp |= reader.ReadByte(); } catch (EndOfStreamException ex) { throw new InvalidDataException("Incomplete data", ex); } n += 3; cdest = curr_size; Console.WriteLine(string.Format("disp: 0x{0:x}", disp)); if (disp > curr_size) { throw new InvalidDataException("Cannot go back more than already written"); } for (int j = 0; j < n; j++) { out_data[curr_size++] = out_data[cdest - disp - 1 + j]; } if (curr_size > decomp_size) break; } else { try { b = reader.ReadByte(); } catch(EndOfStreamException ex) { Console.Error.WriteLine("Incomplete data, " + ex); break; } try { out_data[curr_size++] = (byte)b; } catch(IndexOutOfRangeException ex) { if (b == 0) { break; } } } } } return out_data; }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:59,代码来源:LZ77_WII.cs
在Decompress10LZ()方法中,MemoryStream的代码示例类中的ReadByte的代码示例方法一共出现了4次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.ReadByte的代码示例4 - Decompress()
using System.IO; public Stream Decompress(Stream stream) { using (var reader = new FileReader(stream)) { reader.SetByteOrder(false); var output = new System.IO.MemoryStream(); if (reader.CheckSignature(4, "LZMA", 1)) { byte unk = reader.ReadByte(); //0xFF uint magic = reader.ReadUInt32(); reader.ReadByte(); //padding UseLZMAMagicHeader = true; } byte[] properties = reader.ReadBytes(5); //Property and dictionary size ulong decompressedSize = reader.ReadUInt64(); var compressedSize = stream.Length - reader.Position; var copressedBytes = reader.ReadBytes((int)compressedSize); SevenZip.Compression.LZMA.Decoder decode = new SevenZip.Compression.LZMA.Decoder(); decode.SetDecoderProperties(properties); MemoryStream ms = new MemoryStream(copressedBytes); decode.Code(ms, output, compressedSize, (int)decompressedSize, null); return output; } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:32,代码来源:LZMA.cs
在Decompress()方法中,MemoryStream的代码示例类中的ReadByte的代码示例方法一共出现了2次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.ReadByte的代码示例5 - Supports()
///
/// Checks if the first four (or eight) bytes match the format used in nitro compression formats. /// public override bool Supports(System.IO.Stream stream, long inLength) { long startPosition = stream.Position; try { int firstByte = stream.ReadByte(); if (firstByte != this.magicByte) return false; // no need to read the size info as well if it's used anyway. if (!SkipLargePlaintexts) return true; byte[] sizeBytes = new byte[3]; stream.Read(sizeBytes, 0, 3); int outSize = IOUtils.ToNDSu24(sizeBytes, 0); if (outSize == 0) { sizeBytes = new byte[4]; stream.Read(sizeBytes, 0, 4); outSize = (int)IOUtils.ToNDSu32(sizeBytes, 0); } if (outSize <= MaxPlaintextSize) return true; try { stream.Position = startPosition; this.Decompress(stream, Math.Min(Math.Min(inLength, 0x80000), MaxPlaintextSize), new System.IO.MemoryStream()); // we expect a NotEnoughDataException, since we're giving the decompressor only part of the file. return false; } catch (NotEnoughDataException) { return true; } catch (Exception) { return false; } } finally { stream.Position = startPosition; } }
开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:48,代码来源:NitroCFormat.cs
在Supports()方法中,MemoryStream的代码示例类中的ReadByte的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
MemoryStream.ReadByte的代码示例6 - Dump()
using System.IO; public static void Dump(Stream inStream, int start, int bytesToDump) { using (MemoryStream stream = new MemoryStream()) { if (bytesToDump == -1) { int c = inStream.ReadByte(); while (c != -1) { stream.WriteByte((byte)c); c = inStream.ReadByte(); } } else { int bytesRemaining = bytesToDump; while (bytesRemaining-- > 0) { int c = inStream.ReadByte(); if (c == -1) break; else stream.WriteByte((byte)c); } } byte[] data = stream.ToArray(); Dump(data, 0L, null, start, data.Length); } }
开发者ID:dotnetcore,项目名称:NPOI,代码行数:31,代码来源:HexDump.cs
在Dump()方法中,MemoryStream的代码示例类中的ReadByte的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的MemoryStream.ReadByte方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。