本文整理汇总了C#中Stream.EnsureRead方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.EnsureRead方法的具体用法?C# Stream.EnsureRead怎么用?C# Stream.EnsureRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.EnsureRead方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFromStream
public unsafe void ReadFromStream(Stream input)
{
if (input.Length - input.Position < 16)
return;
byte[] buff = input.EnsureRead(16);
fixed (byte* b = &buff[0])
{
Magic = Endian.ToBigInt32(b + 0);
Count = Endian.ToBigInt32(b + 4);
}
Entries = new WpdEntry[Count];
if (Count < 1)
return;
buff = input.EnsureRead(Count * 32);
fixed (byte* b = &buff[0])
{
for (int i = 0; i < Count; i++)
{
int offset = i * 32;
Entries[i] = new WpdEntry(
i,
new string((sbyte*)b + offset),
Endian.ToBigInt32(b + offset + 16),
Endian.ToBigInt32(b + offset + 20),
new string((sbyte*)b + offset + 24));
}
}
}
示例2: Decrypt
public async Task Decrypt(Stream input, Stream output)
{
_aes.IV = input.EnsureRead(BitConverter.ToInt32(input.EnsureRead(4), 0));
Progress.NullSafeInvoke(4);
using (ICryptoTransform decryptor = _aes.CreateDecryptor())
using (CryptoStream encryptionStream = new CryptoStream(input, decryptor, CryptoStreamMode.Read))
{
if (_cancelEvent.IsSet())
return;
await PatcherService.CopyAsync(encryptionStream, output, _cancelEvent, Progress);
}
}
示例3: FromFileStream
public static DdsHeader FromFileStream(Stream input)
{
byte[] buff = new byte[128];
using (SafeGCHandle handle = new SafeGCHandle(buff, GCHandleType.Pinned))
{
input.EnsureRead(buff, 0, buff.Length);
return (DdsHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject() + 4, TypeCache<DdsHeader>.Type);
}
}
示例4: ReadFromStream
public void ReadFromStream(Stream stream)
{
BinaryReader br = new BinaryReader(stream);
stream.EnsureRead(KeyData, 0, KeyDataSize);
RawBlockOffset = br.ReadInt32();
RawInfoOffset = br.ReadInt32();
EntriesCount = br.ReadInt32();
}
示例5: ReadFromStream
public unsafe void ReadFromStream(Stream stream)
{
byte[] name = stream.EnsureRead(NameSize);
fixed (byte* namePtr = &name[0])
Name = new string((sbyte*)namePtr, 0, NameSize, YkdFile.NamesEncoding).TrimEnd('\0');
Offsets = stream.ReadContent<YkdOffsets>();
Frames = new YkdFrames[Offsets.Count];
for (int i = 0; i < Frames.Length; i++)
Frames[i] = stream.ReadContent<YkdFrames>();
}
示例6: ReadA1B5G5R5Color
private static Color ReadA1B5G5R5Color(Stream input, byte[] buff)
{
input.EnsureRead(buff, 0, 2);
ushort color = BitConverter.ToUInt16(buff, 0);
return Color.FromArgb(
(byte)(((color >> 15) & 1) * 255),
(byte)Math.Round((color & 31) * ColorRate),
(byte)Math.Round((color >> 5 & 31) * ColorRate),
(byte)Math.Round((color >> 10 & 31) * ColorRate));
}
示例7: ReadFromStream
public unsafe void ReadFromStream(Stream stream)
{
byte[] data = stream.EnsureRead(StructSize);
fixed (byte* b = data)
{
PackageNameOffset = Endian.ToBigInt32(b + 0 * 4);
Length = Endian.ToBigInt32(b + 1 * 4);
Dummy = Endian.ToBigInt32(b + 2 * 4);
Offset = Endian.ToBigUInt32(b + 3 * 4);
}
}
示例8: ReadFromStream
public unsafe void ReadFromStream(Stream input)
{
byte[] buff = input.EnsureRead(0x10);
fixed (byte* b = &buff[0])
{
Version = Endian.ToBigInt32(b + 0);
Count = Endian.ToBigInt32(b + 4);
KeysUnpackedSize = Endian.ToBigInt32(b + 8);
TextBlocksCount = Endian.ToBigInt32(b + 12);
}
if (Version != 1)
throw new NotImplementedException();
TextBlockTable = new int[TextBlocksCount];
if (TextBlocksCount > 0)
{
buff = input.EnsureRead(TextBlocksCount * 4);
fixed (byte* b = &buff[0])
{
for (int i = 0; i < TextBlocksCount; i++)
TextBlockTable[i] = Endian.ToBigInt32(b + i * 4);
}
}
TextLinesTable = new ZtrFileHeaderLineInfo[Count];
if (Count > 0)
{
buff = input.EnsureRead(Count * 4);
fixed (byte* b = &buff[0])
{
for (int i = 0; i < Count; i++)
{
TextLinesTable[i].Block = *(b + i * 4);
TextLinesTable[i].BlockOffset = *(b + i * 4 + 1);
TextLinesTable[i].PackedOffset = Endian.ToBigUInt16(b + i * 4 + 2);
}
}
}
}
示例9: ReadFromStream
public void ReadFromStream(Stream stream)
{
BinaryReader br = new BinaryReader(stream);
Magic = br.ReadInt32();
if (Magic != MagicNumber)
throw new Exception("Неверная сигнатура файла: " + Magic);
Type = (SectionType)br.ReadInt32();
Version = br.ReadBigInt32();
Unknown2 = br.ReadBigInt32();
SectionLength = br.ReadBigInt32();
Junk = stream.EnsureRead(28);
}
示例10: ReadFromStream
public static unsafe ZtrFileEncoding ReadFromStream(Stream input)
{
int blockSize;
byte[] buff = input.EnsureRead(4);
fixed (byte* b = &buff[0])
blockSize = Endian.ToBigInt32(b);
byte[] values = new byte[blockSize / 3];
byte[,] encoding = new byte[256, 2];
if (blockSize > 0)
{
buff = input.EnsureRead(blockSize);
fixed (byte* b = &buff[0])
{
for (int i = 0; i < values.Length; i++)
{
byte value = *(b + i * 3);
encoding[value, 0] = *(b + i * 3 + 1);
encoding[value, 1] = *(b + i * 3 + 2);
values[i] = value;
}
}
}
List<byte>[] lists = new List<byte>[256];
for (int i = 0; i < 256; i++)
{
List<byte> list = lists[i] = new List<byte>(16);
DecodeByte(values, encoding, (byte)i, list);
}
byte[][] result = new byte[256][];
for (int i = 0; i < 256; i++)
result[i] = lists[i].ToArray();
return new ZtrFileEncoding(blockSize, result);
}
示例11: ReadBGRAColor
private static Color ReadBGRAColor(Stream input, byte[] buff)
{
input.EnsureRead(buff, 0, 4);
return Color.FromArgb(buff[3], buff[2], buff[1], buff[0]);
}
示例12: ReadB8G8R8Color
private static Color ReadB8G8R8Color(Stream input, byte[] buff)
{
input.EnsureRead(buff, 0, 3);
return Color.FromArgb(255, buff[2], buff[1], buff[0]);
}