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


C# FileStream.Seek方法代码示例

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


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

示例1: Load

 public void Load(BinaryReader br, FileStream fs)
 {
     Offset = br.ReadInt32();
     Offset += 16;
     FrameCount = br.ReadInt32();
     MipWidth = br.ReadInt32();
     MipHeight = br.ReadInt32();
     StartX = br.ReadInt32();
     StartY = br.ReadInt32();
     TileCount = br.ReadUInt16();
     TotalCount = br.ReadUInt16();
     CellWidth = br.ReadUInt16();
     CellHeight = br.ReadUInt16();
     Frames = new EanFrame[TotalCount];
     long curPos = fs.Position;
     fs.Seek((long)Offset, SeekOrigin.Begin);
     for (int i = 0; i < TotalCount; i++)
     {
         Frames[i].X = br.ReadUInt16();
         Frames[i].Y = br.ReadUInt16();
         Frames[i].Width = br.ReadUInt16();
         Frames[i].Height = br.ReadUInt16();
     }
     fs.Seek((long)curPos, SeekOrigin.Begin);
 }
开发者ID:linxiubao,项目名称:UniShader,代码行数:25,代码来源:UVAnimation.cs

示例2: MakeCach

        private static List<FilePathInfo> pathList = new List<FilePathInfo>();//递归过程中解析出来的文件列表

        private static void MakeCach(string vfsPath)
        {
            FileStream fs = new FileStream(vfsPath, FileMode.OpenOrCreate);
            BinaryReader br = new BinaryReader(fs);
            int baseOff = br.ReadInt32();

            int nowIndex = 4;
            while (nowIndex < baseOff)
            {
                int pathLen = br.ReadByte();
                byte[] data = br.ReadBytes(pathLen);
                string pathA = Encoding.ASCII.GetString(data);
                int imgStart = br.ReadInt32();
                int imgEnd = br.ReadInt32();
                nowIndex += 9 + pathLen;

                fs.Seek(imgStart + baseOff, SeekOrigin.Begin);
                byte[] img = br.ReadBytes(imgEnd - imgStart);

                dataDict[pathA] = img;

                fs.Seek(nowIndex, SeekOrigin.Begin);
            }

            br.Close();
            fs.Close();
        }
开发者ID:narlon,项目名称:TOMClassic,代码行数:29,代码来源:NLVFS.cs

示例3: IsGZipHeader

        /// <summary>
        /// Check current file stream postion for header
        /// use this only if current position byte = 0x1F
        /// </summary>
        /// <param name="fs">The stream to check.</param>
        /// <returns>Returns true if the stream a valid gzip header at the current position.</returns>
        public static bool IsGZipHeader(FileStream fs)
        {
            // Read the first ten bytes of the stream
            byte[] header = new byte[HeaderLength - 1];

            int bytesRead = fs.Read(header, 0, header.Length);
            fs.Seek(-bytesRead, SeekOrigin.Current);

            if (bytesRead < header.Length)
            {
                return false;
            }

            // Check the id tokens and compression algorithm
            if (header[0] != 0x8B || header[1] != 0x8)
            {
                return false;
            }

            // Extract the GZIP flags, of which only 5 are allowed (2 pow. 5 = 32)
            if (header[2] > 32)
            {
                return false;
            }

            // Check the extra compression flags, which is either 2 or 4 with the Deflate algorithm
            if (header[7] != 0x0 && header[7] != 0x2 && header[7] != 0x4)
            {
                return false;
            }

            fs.Seek(-1, SeekOrigin.Current);

            return true;
        }
开发者ID:Nokuse,项目名称:GZipTest,代码行数:41,代码来源:ExtensionMethods.cs

示例4: GetMachineType

 public static MachineType GetMachineType(string path) {
   // Open the PE File as a binary file, and parse just enough information to determine the
   // machine type.
   //http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
   using (SafeFileHandle safeHandle =
             NativeMethods.CreateFile(
                 path,
                 NativeAccessFlags.GenericRead,
                 FileShare.Read,
                 IntPtr.Zero,
                 FileMode.Open,
                 FileAttributes.Normal,
                 IntPtr.Zero)) {
     FileStream fs = new FileStream(safeHandle, FileAccess.Read);
     using (BinaryReader br = new BinaryReader(fs)) {
       fs.Seek(0x3c, SeekOrigin.Begin);
       Int32 peOffset = br.ReadInt32();
       fs.Seek(peOffset, SeekOrigin.Begin);
       UInt32 peHead = br.ReadUInt32();
       if (peHead != 0x00004550) // "PE\0\0", little-endian
         throw new Exception("Can't find PE header");
       return (MachineType)br.ReadUInt16();
     }
   }
 }
开发者ID:kleopatra999,项目名称:vs-chromium,代码行数:25,代码来源:ProcessUtility.cs

示例5: FlushSetLengthAtEndOfBuffer

        public void FlushSetLengthAtEndOfBuffer()
        {
            // This is a regression test for a bug with FileStream’s Flush() 
            // and SetLength() methods.
            // The read-buffer was not flushed inside Flush and SetLength when
            // the buffer pointer was at the end. This causes subsequent Seek 
            // and Read calls to operate on stale/wrong data.


            // customer reported repro
            using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
            {
                fs.SetLength(200);
                fs.Flush();

                // write 119 bytes starting from Pos = 28 
                fs.Seek(28, SeekOrigin.Begin);
                Byte[] buffer = new Byte[119];
                for (int i = 0; i < buffer.Length; i++)
                    buffer[i] = Byte.MaxValue;
                fs.Write(buffer, 0, buffer.Length);
                fs.Flush();

                // read 317 bytes starting from Pos = 84;
                fs.Seek(84, SeekOrigin.Begin);
                fs.Read(new byte[1024], 0, 317);

                fs.SetLength(135);
                fs.Flush();

                // read one byte at Pos = 97
                fs.Seek(97, SeekOrigin.Begin);
                Assert.Equal(fs.ReadByte(), (int)Byte.MaxValue);
            }
        }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:35,代码来源:Buffering_regression.cs

示例6: SeekAppendModifyThrows

        public void SeekAppendModifyThrows()
        {
            string fileName = GetTestFilePath();
            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                fs.Write(TestBuffer, 0, TestBuffer.Length);
            }

            using (FileStream fs = new FileStream(fileName, FileMode.Append))
            {
                long length = fs.Length;
                Assert.Throws<IOException>(() => fs.Seek(length - 1, SeekOrigin.Begin));
                Assert.Equal(length, fs.Position);
                Assert.Throws<IOException>(() => fs.Seek(-1, SeekOrigin.Current));
                Assert.Equal(length, fs.Position);
                Assert.Throws<IOException>(() => fs.Seek(-1, SeekOrigin.End));
                Assert.Equal(length, fs.Position);

                Assert.Throws<IOException>(() => fs.Seek(0, SeekOrigin.Begin));
                Assert.Equal(length, fs.Position);
                Assert.Throws<IOException>(() => fs.Seek(-length, SeekOrigin.Current));
                Assert.Equal(length, fs.Position);
                Assert.Throws<IOException>(() => fs.Seek(-length, SeekOrigin.End));
                Assert.Equal(length, fs.Position);
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:26,代码来源:Seek.cs

示例7: GetPEArchitecture

        public static CpuArchitectures GetPEArchitecture(string pFilePath)
        {
            ushort architecture = 0;

            ushort[] coffHeader = new ushort[10];

            using (FileStream fStream = new FileStream(pFilePath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader bReader = new BinaryReader(fStream))
                {
                    if (bReader.ReadUInt16() == 23117) //check the MZ signature
                    {
                        fStream.Seek(0x3A, SeekOrigin.Current); // Go to the location of the location of the NT header
                        fStream.Seek(bReader.ReadUInt32(), SeekOrigin.Begin); // seek to the start of the NT header.
                        if (bReader.ReadUInt32() == 17744) //check the PE\0\0 signature.
                        {
                            for (int i = 0; i < 10; i++) // Read COFF Header
                                coffHeader[i] = bReader.ReadUInt16();
                            if (coffHeader[8] > 0) // Read Optional Header
                                architecture = bReader.ReadUInt16();
                        }
                    }
                }
            }

            switch (architecture)
            {
                case 0x20b:
                    return CpuArchitectures.x64;
                case 0x10b:
                    return ((coffHeader[9] & 0x100) == 0) ? CpuArchitectures.AnyCpu : CpuArchitectures.x86;
                default:
                    return CpuArchitectures.Unknown;
            }
        }
开发者ID:radicalgeek,项目名称:Testing.Smoke,代码行数:35,代码来源:PlatformTest.cs

示例8: GetPackedAssembly

 public static bool GetPackedAssembly(string fileName, out byte[] outBytes)
 {
     FileStream input = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
     int length = (int)input.Length;
     input.Seek(60L, SeekOrigin.Begin);
     BinaryReader reader = new BinaryReader(input);
     int read = reader.ReadInt32();
     if ((read >= 2) && (read <= (length - 512)))
     {
         input.Seek((long)read, SeekOrigin.Begin);
         if (reader.ReadUInt32() == 17744)
         {
             read += 348;
             input.Seek((long)read, SeekOrigin.Begin);
             int read2 = reader.ReadInt32();
             if ((read2 < length) && (read2 >= 768))
             {
                 read2 += 16;
                 length -= read2;
                 byte[] buffer = new byte[length];
                 input.Seek((long)read2, SeekOrigin.Begin);
                 input.Read(buffer, 0, length);
                 input.Close();
                 if (UnpackBytes(buffer, out outBytes, length))
                 {
                     return true;
                 }
             }
         }
     }
     outBytes = null;
     return false;
 }
开发者ID:contra,项目名称:DotCrack,代码行数:33,代码来源:MPRESS.cs

示例9: PEOptionalHeader

        public PEOptionalHeader(FileStream fs) {
            MagicNumber = Utils.ReadShort(fs);

            //Skips
            if (MagicNumber == MAGIC_NUMBER_PE32)
                fs.Seek(90, SeekOrigin.Current);
            else
                fs.Seek(106, SeekOrigin.Current);

            NumberOfRvAndSizes = Utils.ReadInt(fs);
            DataDirectories = new List<PEDataDirectory>();
            if (NumberOfRvAndSizes < 16)
                throw new Exception("Bad format, expected at least 16 directories");
            DataDirectories.Add(new PEDataDirectory(fs,EXPORT_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,IMPORT_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,RESOURCE_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,EXCEPTION_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,CERTIFICATE_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,BASE_RELOCATION_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,DEBUG));
            DataDirectories.Add(new PEDataDirectory(fs,ARCHITECTURE));
            DataDirectories.Add(new PEDataDirectory(fs,GLOBAL_PTR));
            DataDirectories.Add(new PEDataDirectory(fs,TLS_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,LOAD_CONFIG_TABLE));
            DataDirectories.Add(new PEDataDirectory(fs,BOUND_IMPORT));
            DataDirectories.Add(new PEDataDirectory(fs,IAT));
            DataDirectories.Add(new PEDataDirectory(fs,DELAY_IMPORT_DESCRIPTOR));
            DataDirectories.Add(new PEDataDirectory(fs,CLR_RUNTIME_HEADER));
            DataDirectories.Add(new PEDataDirectory(fs,RESERVED));
            for (int i = 16; i < NumberOfRvAndSizes; i++)
                DataDirectories.Add(new PEDataDirectory(fs, "Unknown"));
        }
开发者ID:nanrajred,项目名称:cbloader,代码行数:32,代码来源:PEOptionalHeader.cs

示例10: CabeceraSF

        public CabeceraSF(string fichero)
        {
            FileStream reader = null;

            try{
                reader = new FileStream (fichero, FileMode.Open);
                reader.Seek(4,SeekOrigin.Begin);
                int contador = 4;
                do{
                    contador++;
                }while ((contador < LIMITE) && (contador < reader.Length) && (reader.ReadByte()!= 0));
                //TODO: Poner limite al while

                reader.Seek(0, SeekOrigin.Begin);
                byte[] b = new byte[contador];
                reader.Read (b, 0, contador);

                if ((b[0]!=0x53) || (b[1]!=0x46) || (b[2]!=0) || (b[3]!=0) || (b[4] != 6)){
                    // TODO: Poner una excepcion personalizada
                    throw new Exception();
                }
                numero = b[5];
                nombre = "";
                for (int i=6; (i < b.Length) && (b[i]!=0); i++)
                    nombre += Convert.ToChar(b[i]);
            }
            catch (Exception){
                throw;
            }
            finally{
                if (reader != null){
                    reader.Close();
                }
            }
        }
开发者ID:albfernandez,项目名称:dalle,代码行数:35,代码来源:CabeceraSF.cs

示例11: GetDataInputStream

        public virtual Stream GetDataInputStream(CompressionType compression)
        {
            try {
                switch (compression)
                {
                    case CompressionType.None:
                        using (FileStream fstr = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            long length = fstr.Seek(0, SeekOrigin.End);
                            fstr.Seek(0, SeekOrigin.Begin);

                            byte[] data = new byte[length];
                            fstr.Read(data, 0, data.Length);

                            return new MemoryStream(data);
                        }
                    case CompressionType.GZip:
                        Stream stream1 = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        return new GZipStream(stream1, CompressionMode.Decompress);
                    case CompressionType.Zlib:
                        Stream stream2 = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        return new ZlibStream(stream2, CompressionMode.Decompress);
                    case CompressionType.Deflate:
                        Stream stream3 = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        return new DeflateStream(stream3, CompressionMode.Decompress);
                    default:
                        throw new ArgumentException("Invalid CompressionType specified", "compression");
                }
            }
            catch (Exception ex) {
                throw new NbtIOException("Failed to open compressed NBT data stream for input.", ex);
            }
        }
开发者ID:omglolbah,项目名称:Blightfall,代码行数:33,代码来源:NBTFile.cs

示例12: RaceSfv

 public void RaceSfv()
 {
     CleanTestFilesOutput();
     Race race = UploadSfvFile ();
     FileInfo fileInfo = new FileInfo (Misc.PathCombine (race.CurrentRaceData.DirectoryPath, Config.FileNameRace));
     using (FileStream stream = new FileStream (fileInfo.FullName,
                                                FileMode.OpenOrCreate,
                                                FileAccess.ReadWrite,
                                                FileShare.None))
     {
         using (BinaryReader reader = new BinaryReader (stream))
         {
             stream.Seek (0, SeekOrigin.Begin);
             Assert.AreEqual (4, reader.ReadInt32 (), "Expected integer value (4)");
             stream.Seek(256 * 1, SeekOrigin.Begin);
             Assert.AreEqual("infected.part1.rar", reader.ReadString(), "infected.part1.rar");
             Assert.AreEqual("2e04944c", reader.ReadString(), "2e04944c");
             Assert.AreEqual(false, reader.ReadBoolean(), "FileUploaded");
             stream.Seek(256 * 2, SeekOrigin.Begin);
             Assert.AreEqual("infected.part2.rar", reader.ReadString(), "infected.part2.rar");
             Assert.AreEqual("1c7c24a5", reader.ReadString(), "1c7c24a5");
             Assert.AreEqual(false, reader.ReadBoolean(), "FileUploaded");
             stream.Seek(256 * 3, SeekOrigin.Begin);
             Assert.AreEqual("infected.part3.rar", reader.ReadString(), "infected.part3.rar");
             Assert.AreEqual("d5d617e3", reader.ReadString(), "d5d617e3");
             Assert.AreEqual(false, reader.ReadBoolean(), "FileUploaded");
             stream.Seek(256 * 4, SeekOrigin.Begin);
             Assert.AreEqual("infected.part4.rar", reader.ReadString(), "infected.part4.rar");
             Assert.AreEqual("0edb20ea", reader.ReadString(), "0edb20ea");
             Assert.AreEqual(false, reader.ReadBoolean(), "FileUploaded");
         }
     }
 }
开发者ID:trippleflux,项目名称:jezatools,代码行数:33,代码来源:SfvTests.cs

示例13: ReadCollection

        public static ObjectInfo[] ReadCollection(string path)
        {
            Stream stream = new FileStream(path, FileMode.Open);

            BinaryReader binaryReader = new BinaryReader(stream);
            int count = binaryReader.ReadInt32();
            ObjectInfo[] infoCollection = new ObjectInfo[count];
            infoCollection[0] = new ObjectInfo { height = 0, indices = new int[0] };
            for (int index = 0; index < count; ++index)
            {
                if (index == 0)
                {
                    ObjectInfo info = infoCollection[index] = new ObjectInfo();
                    info.height = binaryReader.ReadByte();
                    info.indices = new int[info.height];
                    info.indices[0] = binaryReader.ReadByte();
                    stream.Seek(6, SeekOrigin.Current);
                }
                else
                {
                    ObjectInfo info = infoCollection[index] = new ObjectInfo();
                    info.height = binaryReader.ReadByte();
                    info.indices = new int[info.height];
                    for (int subIndex = 0; subIndex < info.height; subIndex++)
                        info.indices[subIndex] = binaryReader.ReadUInt16();
                    Array.Reverse(info.indices);
                    stream.Seek(6, SeekOrigin.Current);
                }
            }

            binaryReader.Close();
            stream.Dispose();
            return infoCollection;
        }
开发者ID:jaggedsoft,项目名称:mithiamapeditor,代码行数:34,代码来源:ObjectInfo.cs

示例14: Initialize

		public static void Initialize()
		{
			string path = Files.GetFilePath("skillgrp.mul");

			List = new List<SkillGroup>();
			SkillList = new List<int>();

			if (path != null)
			{
				using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					using (var bin = new BinaryReader(fs))
					{
						int start = 4;
						int strlen = 17;
						int count = bin.ReadInt32();
						if (count == -1)
						{
							unicode = true;
							count = bin.ReadInt32();
							start *= 2;
							strlen *= 2;
						}

						List.Add(new SkillGroup("Misc"));
						for (int i = 0; i < count - 1; ++i)
						{
							int strbuild;
							fs.Seek((start + (i * strlen)), SeekOrigin.Begin);
							var builder2 = new StringBuilder(17);
							if (unicode)
							{
								while ((strbuild = bin.ReadInt16()) != 0)
								{
									builder2.Append((char)strbuild);
								}
							}
							else
							{
								while ((strbuild = bin.ReadByte()) != 0)
								{
									builder2.Append((char)strbuild);
								}
							}
							List.Add(new SkillGroup(builder2.ToString()));
						}
						fs.Seek((start + ((count - 1) * strlen)), SeekOrigin.Begin);
						try
						{
							while (bin.BaseStream.Length != bin.BaseStream.Position)
							{
								SkillList.Add(bin.ReadInt32());
							}
						}
						catch // just for safety
						{ }
					}
				}
			}
		}
开发者ID:Crome696,项目名称:ServUO,代码行数:60,代码来源:SkillGroups.cs

示例15: getMd5Hash

        /// <summary>
        /// 获取文件MD5
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string getMd5Hash(string filePath, int type)
        {
            string smd5 = filePath;
            try
            {
                using (FileStream t = new FileStream(filePath, FileMode.Open))
                {
                    int l = 1024;
                    long l1 = t.Length / 3;
                    long l2 = t.Length / 2;
                    if (l1 < l)
                    {
                        l = (int)l1;
                    }
                    byte[] begin = new byte[l];
                    byte[] middle = new byte[l];
                    byte[] end = new byte[l];
                    t.Seek(0, SeekOrigin.Begin);
                    t.Read(begin, 0, begin.Length);

                    t.Seek(l2, SeekOrigin.Begin);
                    t.Read(middle, 0, middle.Length);

                    t.Seek(t.Length - end.Length, SeekOrigin.Begin);
                    t.Read(end, 0, end.Length);

                    string body = UnTo.byteToIntStr(begin) + UnTo.byteToIntStr(middle) + UnTo.byteToIntStr(end);
                    return getMd5Hash(body);
                }
            }
            catch
            {
                return getMd5Hash(filePath);
            }
        }
开发者ID:xxgkgk,项目名称:UnifyNet,代码行数:41,代码来源:UnEncMD5.cs


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