当前位置: 首页>>代码示例>>C#>>正文


C# Stream.EnsureRead方法代码示例

本文整理汇总了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));
                }
            }
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:32,代码来源:WpdHeader.cs

示例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);
            }
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:14,代码来源:CryptoProvider.cs

示例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);
     }
 }
开发者ID:kidaa,项目名称:Pulse,代码行数:9,代码来源:DdsHeaderDecoder.cs

示例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();
        }
开发者ID:truongan012,项目名称:Pulse,代码行数:9,代码来源:ArchiveListingHeaderV2.cs

示例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>();
        }
开发者ID:truongan012,项目名称:Pulse,代码行数:11,代码来源:YkdBlockEntry.cs

示例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));
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:11,代码来源:ColorsHelper.cs

示例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);
     }
 }
开发者ID:truongan012,项目名称:Pulse,代码行数:11,代码来源:WdbMovieEntry.cs

示例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);
                    }
                }
            }
        }
开发者ID:truongan012,项目名称:Pulse,代码行数:40,代码来源:ZtrFileHeader.cs

示例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);
        }
开发者ID:truongan012,项目名称:Pulse,代码行数:13,代码来源:SectionHeader.cs

示例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);
        }
开发者ID:kidaa,项目名称:Pulse,代码行数:37,代码来源:ZtrFileEncoding.cs

示例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]);
 }
开发者ID:kidaa,项目名称:Pulse,代码行数:5,代码来源:ColorsHelper.cs

示例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]);
 }
开发者ID:kidaa,项目名称:Pulse,代码行数:5,代码来源:ColorsHelper.cs


注:本文中的Stream.EnsureRead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。