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


C# Stream.Seek方法代码示例

本文整理汇总了C#中Stream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.Seek方法的具体用法?C# Stream.Seek怎么用?C# Stream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream.Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InternalWrite

        protected override void InternalWrite(Stream Target)
        {
            Target.Seek(0, SeekOrigin.Begin);
            Target.Write(ByteHelper.StringToByte("ID3"));
            //                Version 3.0   Flags  dummy size
            Target.Write(new byte[] { 3,0,  0,     0, 0, 0, 0  }, 0, 7);

            long totalFrameSize = 0;
            Stream frameStream = null;
            foreach(Frame f in Frames)
            {
                frameStream = FrameObjectToByteArray(f);
                totalFrameSize += frameStream.Length;
                frameStream.CopyTo(Target);
                frameStream.Flush();
            }
            Target.Seek(6, SeekOrigin.Begin);
            Target.Write(ByteHelper.GetByteArrayWith7SignificantBitsPerByteForInt((int)totalFrameSize));

            // frame fertig geschrieben jetzt müssen die daten rein =>
            // sourcestream an die stelle spulen und lesen bis endpos
            Target.Seek(DataStart, SeekOrigin.Begin);

            // Target.Copy(SourceStream, DataStart, DataEnd);

            Target.Flush();
            Target.Close();
        }
开发者ID:Epibatidin,项目名称:FLUX,代码行数:28,代码来源:ID3V23.cs

示例2: WriteToWav

        public static void WriteToWav(Stream RawData, Stream Output, AudioFormat AudioFormat)
        {
            if (AudioFormat.WaveFormat != WaveFormatType.Pcm) throw new ArgumentException("You can write only to WAV.");

            BinaryWriter bwOutput = new BinaryWriter(Output);

            //WAV header
            bwOutput.Write("RIFF".ToCharArray());
            bwOutput.Write((uint)(RawData.Length + 36));
            bwOutput.Write("WAVE".ToCharArray());
            bwOutput.Write("fmt ".ToCharArray());
            bwOutput.Write((uint)0x10);
            bwOutput.Write((ushort)0x01);
            bwOutput.Write((ushort)AudioFormat.Channels);
            bwOutput.Write((uint)AudioFormat.SamplesPerSecond);
            bwOutput.Write((uint)(AudioFormat.BitsPerSample * AudioFormat.SamplesPerSecond * AudioFormat.Channels / 8));
            bwOutput.Write((ushort)(AudioFormat.BitsPerSample * AudioFormat.Channels / 8));
            bwOutput.Write((ushort)AudioFormat.BitsPerSample);
            bwOutput.Write("data".ToCharArray());
            bwOutput.Write((uint)RawData.Length);


            long originalRawDataStreamPosition = RawData.Position;
            RawData.Seek(0, SeekOrigin.Begin);
            byte[] buffer = new byte[4096];
            int read;
            while ((read = RawData.Read(buffer, 0, 4096)) > 0)
            {
                bwOutput.Write(buffer, 0, read);
            }
            RawData.Seek(originalRawDataStreamPosition, SeekOrigin.Begin);
        }
开发者ID:deha,项目名称:NoteShare.Media,代码行数:32,代码来源:WavWritter.cs

示例3: CreateV1Frames

        private void CreateV1Frames(Stream stream)
        {
            // ID1 header am ende ...
            stream.Seek(-125, SeekOrigin.End);
            // 30 zeichen title     => TIT2
            // 30 zeichen artist    => TCOM
            // 30 zeichen album     => TALB
            // 4 zeichen jahr       => TYER
            // 30 zeichen commentar - kann auch den track enthalten (TRCK) - der letzte byte
            // 1 byte Genre
            // == 125

            foreach (var item in new[] { "TIT2", "TCOM", "TALB" })
            {
                AddFrame(item, ByteHelper.BytesToString(stream.Read(30)));
            }
            AddFrame("TYER", ByteHelper.BytesToString(stream.Read(4)));

            // comment - egal
            stream.Seek(28, SeekOrigin.Current);
            var track = stream.Read(2);
            if (track[0] == 0 && track[1] != 0)
            {
                // dann ist track[1] eine zahl;
                if (track[1] < 48)
                {
                    AddFrame("TRCK",((int)track[1]).ToString());
                }
            }
        }
开发者ID:Epibatidin,项目名称:FLUX,代码行数:30,代码来源:ID3V23TagReader.cs

示例4: CopyStream

        public static void CopyStream(Stream source, Stream dest, bool rewindSource)
        {
            long restorePosition1 = -1;

            if (source.CanSeek)
            {

                restorePosition1 = source.Position;

                if (rewindSource)
                    source.Seek(0, SeekOrigin.Begin);
            }
            else
            {
                if (rewindSource)
                    throw new Exception("Can't rewind source");
            }

            byte[] buffer = new byte[bufferSize];
            int readAmount;
            int readOffset = 0;
            while ((readAmount = source.Read(buffer, readOffset, bufferSize)) > 0)
            {
                dest.Write(buffer, 0, readAmount);
            }

            if (source.CanSeek)
                source.Seek(restorePosition1, SeekOrigin.Begin);
        }
开发者ID:Mavtak,项目名称:WebCommunicator,代码行数:29,代码来源:StreamUtilities.cs

示例5: GetPEFileKinds

 private static PEFileKinds GetPEFileKinds(Stream s)
 {
     var rawPeSignatureOffset = new byte[4];
     s.Seek(0x3c, SeekOrigin.Begin);
     s.Read(rawPeSignatureOffset, 0, 4);
     int peSignatureOffset = rawPeSignatureOffset[0];
     peSignatureOffset |= rawPeSignatureOffset[1] << 8;
     peSignatureOffset |= rawPeSignatureOffset[2] << 16;
     peSignatureOffset |= rawPeSignatureOffset[3] << 24;
     var coffHeader = new byte[24];
     s.Seek(peSignatureOffset, SeekOrigin.Begin);
     s.Read(coffHeader, 0, 24);
     byte[] signature = { (byte)'P', (byte)'E', (byte)'\0', (byte)'\0' };
     for (int index = 0; index < 4; index++)
     {
         if (coffHeader[index] != signature[index]) throw new InvalidOperationException("Attempted to check a non PE file for the console subsystem!");
     }
     var subsystemBytes = new byte[2];
     s.Seek(68, SeekOrigin.Current);
     s.Read(subsystemBytes, 0, 2);
     int subSystem = subsystemBytes[0] | subsystemBytes[1] << 8;
     return
         // http://support.microsoft.com/kb/90493
         subSystem == 3 ? PEFileKinds.ConsoleApplication :
         subSystem == 2 ? PEFileKinds.WindowApplication :
         PEFileKinds.Dll; /*IMAGE_SUBSYSTEM_WINDOWS_CUI*/
 }
开发者ID:BiYiTuan,项目名称:soa,代码行数:27,代码来源:Runtime.cs

示例6: WriteDataCommand

        public void WriteDataCommand(Stream source, long offset, long length)
        {
            writer.Write(BinaryFormat.DataCommand);
            writer.Write(length);

            var originalPosition = source.Position;
            try
            {
                source.Seek(offset, SeekOrigin.Begin);

                var buffer = new byte[1024 * 1024];

                int read;
                do
                {
                    read = source.Read(buffer, 0, buffer.Length);

                    writer.Write(buffer, 0, read);
                } while (read > 0);
            }
            finally
            {
                source.Seek(originalPosition, SeekOrigin.Begin);
            }
        }
开发者ID:mahmoud-samy-symbyo,项目名称:Octodiff,代码行数:25,代码来源:BinaryDeltaWriter.cs

示例7: Open

        public bool Open(Stream fs)
        {
            Header = MarshalUtil.ReadStruct<CBMD>(fs); //read header

            //-- Graphics Reading --

            //Read ahead the size of the uncompressed file
            fs.Seek(Header.CompressedCGFXOffset + 1, SeekOrigin.Begin);
            var intBytes = new byte[4];
            fs.Read(intBytes, 0, 4);
            DecompressedCGFX = new byte[BitConverter.ToUInt32(intBytes, 0)];
            //Read again from the start
            fs.Seek(Header.CompressedCGFXOffset, SeekOrigin.Begin);
            var ms = new MemoryStream(DecompressedCGFX);
            try
            {
                var lz11 = new DSDecmp.Formats.Nitro.LZ11();
                lz11.Decompress(fs, Header.CBMDLength - fs.Position, ms);
            }
            catch
            { //might throw exception if size of compressed is bigger than it should be
            }
            ms.Seek(0, SeekOrigin.Begin);
            CGFXContext = new CGFXContext();
            CGFXContext.Open(ms);
            return true;
        }
开发者ID:dr1s,项目名称:rom_tool,代码行数:27,代码来源:mdlCBMD.cs

示例8: getSSMBase

 public static string getSSMBase(Stream imageStream)
 {
     byte[] byc = new byte[4];
     long highlimit = 5000000;
     long lowlimit = 100000;
     long difflimit = 100000;
     if (imageStream.Length < highlimit)
         highlimit = imageStream.Length;
     for (long i = lowlimit; i < highlimit; i += 4)
     {
         long start = i;
         imageStream.Seek(i, SeekOrigin.Begin);
         if (SSMBaseRecursion(imageStream, i, 0, 0, difflimit))
             return start.ToString("X");
         else
             continue;
     }
     difflimit += 40000;
     for (long i = lowlimit; i < highlimit; i += 4)
     {
         long start = i;
         imageStream.Seek(i, SeekOrigin.Begin);
         if (SSMBaseRecursion(imageStream, i, 0, 0, difflimit))
             return start.ToString("X");
         else
             continue;
     }
     return "Enter SSM Base";
 }
开发者ID:Merp,项目名称:SharpTune,代码行数:29,代码来源:SSMBase.cs

示例9: ParseIndex

        private void ParseIndex(Stream stream, int i)
        {
            using (var br = new BinaryReader(stream))
            {
                stream.Seek(-12, SeekOrigin.End);
                int count = br.ReadInt32();
                stream.Seek(0, SeekOrigin.Begin);

                if (count * (16 + 4 + 4) > stream.Length)
                    throw new Exception("ParseIndex failed");

                for (int j = 0; j < count; ++j)
                {
                    byte[] key = br.ReadBytes(16);

                    if (key.IsZeroed()) // wtf?
                        key = br.ReadBytes(16);

                    if (key.IsZeroed()) // wtf?
                        throw new Exception("key.IsZeroed()");

                    IndexEntry entry = new IndexEntry();
                    entry.Index = i;
                    entry.Size = br.ReadInt32BE();
                    entry.Offset = br.ReadInt32BE();

                    CDNIndexData.Add(key, entry);
                }
            }
        }
开发者ID:hurricup,项目名称:CASCExplorer,代码行数:30,代码来源:CDNIndexHandler.cs

示例10: FromStream

        public void FromStream(Stream stream, int size)
        {
            long start = stream.Position;

            BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);

            ushort magic = reader.ReadUInt16();

            stream.Seek(start, SeekOrigin.Begin);

            _optionalHeaderBase = null;

            switch (magic)
            {
            case Constants.IMAGE_NT_OPTIONAL_HDR32_MAGIC:
                _optionalHeaderBase = new OptionalHeaderPE32();
                break;
            case Constants.IMAGE_NT_OPTIONAL_HDR64_MAGIC:
                _optionalHeaderBase = new OptionalHeaderPE64();
                break;
            case Constants.IMAGE_ROM_OPTIONAL_HDR_MAGIC:
                //_optionalHeaderBase = new OptionalHeaderPE32();
                //break;
            default:
                break;
            }

            if (_optionalHeaderBase != null)
            {
                _optionalHeaderBase.FromStream(stream);
            }

            stream.Seek(start + size, SeekOrigin.Begin);
        }
开发者ID:BlazingHeart,项目名称:SymbolExplorer,代码行数:34,代码来源:OptionalHeader.cs

示例11: Packfile

        public Packfile(Stream stream, bool isStr2)
        {
            IsStr2 = isStr2;
            stream.Seek(0, SeekOrigin.Begin);
            FileData = stream.ReadStruct<PackfileFileData>();

            m_Files = new List<IPackfileEntry>();

            uint runningPosition = 0;
            List<PackfileEntryFileData> entryFileData = new List<PackfileEntryFileData>();
            for (int i = 0; i < FileData.NumFiles; i++)
            {
                PackfileEntryFileData data = stream.ReadStruct<PackfileEntryFileData>();

                if (IsCondensed && IsCompressed)
                {
                    data.Flags = 0;
                    data.Start = runningPosition;
                    runningPosition += data.Size;
                }
                else if (IsCondensed)
                {
                    data.Start = runningPosition;
                    runningPosition += data.Size.Align(16);
                }

                entryFileData.Add(data);
            }

            for (int i = 0; i < FileData.NumFiles; i++)
            {
                stream.Align(2);
                string filename = stream.ReadAsciiNullTerminatedString();
                stream.Seek(1, SeekOrigin.Current);
                m_Files.Add(new PackfileEntry(this, entryFileData[i], filename));
                stream.Align(2);
            }

            if (IsCondensed && IsCompressed)
            {
                DataOffset = 0;
                byte[] compressedData = new byte[FileData.CompressedDataSize];
                stream.Read(compressedData, 0, (int)FileData.CompressedDataSize);
                using (MemoryStream tempStream = new MemoryStream(compressedData))
                {
                    using (Stream s = new ZlibStream(tempStream, CompressionMode.Decompress, true))
                    {
                        byte[] uncompressedData = new byte[FileData.DataSize];
                        s.Read(uncompressedData, 0, (int)FileData.DataSize);
                        DataStream = new MemoryStream(uncompressedData);
                    }
                }
                
            }
            else
            {
                DataStream = stream;
                DataOffset = stream.Position;
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:60,代码来源:Packfile.cs

示例12: Deserialize

        public static ISavegame Deserialize(Stream stream)
        {
            if (stream == null) throw new ArgumentNullException(nameof(stream));

            if (stream.Position != 0)
                stream.Seek(0, SeekOrigin.Begin);

            var checkBuffer = new byte[2];
            stream.Read(checkBuffer, 0, 2);
            stream.Seek(0, SeekOrigin.Begin);

            if (checkBuffer.SequenceEqual(new byte[] {0x1f, 0x8b}))
            {
                using (var gZipStream = new GZipStream(stream, CompressionMode.Decompress))
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        gZipStream.CopyTo(memoryStream);
                        return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
                    }
                }
            }

            if (stream is MemoryStream)
            {
                var memoryStream = (MemoryStream) stream;
                return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
            }

            using (var memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                return Deserialize(Encoding.UTF8.GetString(memoryStream.ToArray()));
            }
        }
开发者ID:ParkitectNexus,项目名称:AssetMagic,代码行数:35,代码来源:SavegameConverter.cs

示例13: Load

        public unsafe MultiIcon Load(Stream stream)
        {
            stream.Position = 0;
            SingleIcon singleIcon = new SingleIcon("Untitled");
            ICONDIR iconDir = new ICONDIR(stream);
            if (iconDir.idReserved != 0)
                throw new InvalidMultiIconFileException();

            if (iconDir.idType != 1)
                throw new InvalidMultiIconFileException();

            int entryOffset = sizeof(ICONDIR);

            // Add Icon Images one by one to the new entry created
            for(int i=0; i<iconDir.idCount; i++)
            {
                stream.Seek(entryOffset, SeekOrigin.Begin);
                ICONDIRENTRY entry = new ICONDIRENTRY(stream);

                // If there is missing information in the header... lets try to calculate it
                entry = CheckAndRepairEntry(entry);

                stream.Seek(entry.dwImageOffset, SeekOrigin.Begin);

                singleIcon.Add(new IconImage(stream, (int) (stream.Length - stream.Position)));
                entryOffset += sizeof(ICONDIRENTRY);
            }

            return new MultiIcon(singleIcon);
        }
开发者ID:Jamedjo,项目名称:IconLib,代码行数:30,代码来源:IconFormat.cs

示例14: Deserialize

        public void Deserialize(Stream input)
        {
            input.Seek(0, SeekOrigin.Begin);

            var header = input.ReadStructure<SimGroup.FileHeader>();

            if (header.HeaderSize < Marshal.SizeOf(header) ||
                header.HeaderSize > input.Length)
            {
                throw new FormatException("bad data size");
            }

            uint[] unknown08s = new uint[header.Unknown14Count];
            input.Seek(header.Unknown08Offset, SeekOrigin.Begin);
            for (ushort i = 0; i < header.Unknown14Count; i++)
            {
                unknown08s[i] = input.ReadValueU32();
            }

            input.Seek(header.Unknown0COffset, SeekOrigin.Begin);
            for (ushort i = 0; i < header.Unknown16Count; i++)
            {

            }
        }
开发者ID:tgp1994,项目名称:Gibbed.Visceral,代码行数:25,代码来源:SimGroupFile.cs

示例15: Load

 public void Load(Stream data, bool fast = false)
 {
     uint headersize = Helpers.ReadLEUInt(data);
     long startoffset = data.Position;
     Header = new HeaderStruct();
     Header.magic = Helpers.ReadLEUInt(data);
     Header.totalCount = Helpers.ReadLEUInt(data);
     Header.ebxCount = Helpers.ReadLEUInt(data);
     Header.resCount = Helpers.ReadLEUInt(data);
     Header.chunkCount = Helpers.ReadLEUInt(data);
     Header.stringOffset = Helpers.ReadLEUInt(data);
     Header.chunkMetaOffset = Helpers.ReadLEUInt(data);
     Header.chunkMetaSize = Helpers.ReadLEUInt(data);
     ReadSha1List(data);
     ReadEbxList(data);
     ReadResList(data);
     ReadChunkList(data);
     if (Header.chunkCount != 0)
         ChunkMeta = BJSON.ReadField(data);
     else
         ChunkMeta = null;
     data.Seek(startoffset + Header.stringOffset, 0);
     ReadEbxListNames(data);
     data.Seek(startoffset + Header.stringOffset, 0);
     ReadResListNames(data);
     data.Seek(startoffset + headersize, 0);
     ReadEbxListData(data, fast);
     ReadResListData(data, fast);
     ReadChunkListData(data, fast);
     ApplySHA1s();
 }
开发者ID:tirnoney,项目名称:DAIToolsWV,代码行数:31,代码来源:BinaryBundle.cs


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