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


C# GZipStream.WriteByte方法代码示例

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


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

示例1: CompressStream

 /// <summary>
 /// Wraps the given stream in a compression stream.
 /// </summary>
 /// <param name="output">Stream to wrap.</param>
 /// <returns>Compression stream to which data can be written.</returns>
 public static Stream CompressStream(Stream output)
 {
     Stream result = new GZipStream(output, CompressionMode.Compress);
     result.WriteByte(0xff & (MagicNumber >> 24));
     result.WriteByte(0xff & (MagicNumber >> 16));
     result.WriteByte(0xff & (MagicNumber >> 8));
     result.WriteByte(0xff & (MagicNumber));
     return result;
 }
开发者ID:5342,项目名称:C5SIGMA,代码行数:14,代码来源:CompressionSupport.cs

示例2: Save

        public static void Save(Level level, string file) {
            using (Stream fs = File.Create(file),
                   gs = new GZipStream(fs, CompressionMode.Compress, true))
            {
                byte[] header = new byte[16];
                BitConverter.GetBytes(1874).CopyTo(header, 0);
                gs.Write(header, 0, 2);

                BitConverter.GetBytes(level.Width).CopyTo(header, 0);
                BitConverter.GetBytes(level.Length).CopyTo(header, 2);
                BitConverter.GetBytes(level.Height).CopyTo(header, 4);
                BitConverter.GetBytes(level.spawnx).CopyTo(header, 6);
                BitConverter.GetBytes(level.spawnz).CopyTo(header, 8);
                BitConverter.GetBytes(level.spawny).CopyTo(header, 10);
                header[12] = level.rotx;
                header[13] = level.roty;
                header[14] = (byte)level.permissionvisit;
                header[15] = (byte)level.permissionbuild;
                gs.Write(header, 0, header.Length);
                byte[] blocks = level.blocks;
                byte[] convBlocks = new byte[blocks.Length];

                for (int i = 0; i < blocks.Length; ++i) {
                    byte block = blocks[i];
                    if (block < Block.CpeCount) {
                        convBlocks[i] = block; //CHANGED THIS TO INCOPARATE SOME MORE SPACE THAT I NEEDED FOR THE door_orange_air ETC.
                    } else {
                        convBlocks[i] = Block.SaveConvert(block);
                    }
                }
                gs.Write(convBlocks, 0, convBlocks.Length);
                
                // write out new blockdefinitions data
                gs.WriteByte(0xBD);
                int index = 0;
                for (int y = 0; y < level.ChunksY; y++)
                	for (int z = 0; z < level.ChunksZ; z++)
                		for (int x = 0; x < level.ChunksX; x++)
                {
                    byte[] chunk = level.CustomBlocks[index];
                    if (chunk == null) {
                        gs.WriteByte(0);
                    } else {
                        gs.WriteByte(1);
                        gs.Write(chunk, 0, chunk.Length);
                    }
                    index++;
                }
            }
        }
开发者ID:tommyz56,项目名称:MCGalaxy,代码行数:50,代码来源:LvlFile.cs

示例3: CompressFile

 static void CompressFile(string inFilename, string outFilename)
 {
     FileStream sourceFile = File.OpenRead(inFilename);
     FileStream destFile = File.Create(outFilename);
     GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);
     int theByte = sourceFile.ReadByte();
     while (theByte != -1)
     {
         compStream.WriteByte((byte)theByte);
         theByte = sourceFile.ReadByte();
     }
     sourceFile.Close();
     destFile.Close();
     compStream.Close();
 }
开发者ID:danaibraimova,项目名称:oop,代码行数:15,代码来源:Program.cs

示例4: Compress

        public byte[] Compress(byte[] fileBytes)
        {
            byte[] bytes;

            using (MemoryStream fileStream = new MemoryStream(fileBytes)) {
                using (MemoryStream compressedStream = new MemoryStream()) {
                    using (GZipStream zipStream = new GZipStream(compressedStream, CompressionMode.Compress)) {
                        int value;
                        while ((value = fileStream.ReadByte()) != -1) {
                            zipStream.WriteByte((byte) value);
                        }
                        zipStream.Close();
                        bytes = compressedStream.ToArray();
                    }
                }
            }

            return bytes;
        }
开发者ID:stewmc,项目名称:vixen,代码行数:19,代码来源:FileCompressor.cs

示例5: Main

        static void Main()
        {
            // Создание файла и архива.
            FileStream source = File.OpenRead(@"D:\test.txt");
            FileStream destination = File.Create(@"D:\archive.zip");

            // Создание компрессора.
            GZipStream compressor = new GZipStream(destination, CompressionMode.Compress);

            // Заполнение архива информацией из файла.
            int theByte = source.ReadByte();
            while (theByte != -1)
            {
                compressor.WriteByte((byte)theByte);
                theByte = source.ReadByte();
            }

            // Удаление компрессора.
            compressor.Close();
        }
开发者ID:vbre,项目名称:CS_2015_Winter,代码行数:20,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            FileStream sourceFile = File.OpenRead(@"d.txt");
            FileStream destFile = File.Create(@"sample.zip");

            GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);

            try
            {
                int theByte = sourceFile.ReadByte();
                while (theByte != -1)
                {
                    compStream.WriteByte((byte)theByte);
                    theByte = sourceFile.ReadByte();
                }
            }
            finally
            {
                compStream.Dispose();
            } 
        }
开发者ID:d-kakhiani,项目名称:C_Sharp,代码行数:21,代码来源:Program.cs

示例7: ToStream

 public void ToStream(Stream writestream)
 {
     GZipStream gZipStream = null;
         try
         {
             System.Windows.MessageBox.Show(Convert.ToString(this.Filedata.Length));
             gZipStream = new GZipStream(writestream, CompressionMode.Compress, true);
             gZipStream.Write(this.Filedata, 0, (int)this.Filedata.Length);
             gZipStream.WriteByte(255);
             //gZipStream.Write(this.Screenshot, 0, (int)this.Screenshot.Length);
         }
         finally
         {
             if (gZipStream != null)
             {
                 gZipStream.Close();
             }
         }
         return;
 }
开发者ID:GENiEBEN,项目名称:cheetah-hwbotaqua-v1,代码行数:20,代码来源:Window1.xaml.cs

示例8: CompressFile

		// Compresses the given file, and optionally deletes the source file when finished
		private void CompressFile(string fileName, bool deleteFile = true)
		{
			// zip up the file, taking the compression level from the configuration
			var zipFileName = String.Format(ZipPattern, fileName);

			using (var fileStream = File.OpenRead(fileName))
			using (var destFile = File.Create(zipFileName))
			using (var compStream = new GZipStream(destFile, CompressionLevel.Optimal))
			{
				int theByte = fileStream.ReadByte();
				while (theByte != -1)
				{
					compStream.WriteByte((byte)theByte);
					theByte = fileStream.ReadByte();
				}
			}

			if (deleteFile)
				File.Delete(fileName);
		}
开发者ID:ivanpointer,项目名称:NuLog,代码行数:21,代码来源:TextFileTarget.cs

示例9: GZip

        public static byte[] GZip(byte[] mapSize, byte[] levelData)
        {
            var ms = new MemoryStream();
            var gs = new GZipStream(ms, CompressionMode.Compress, true);
            gs.Write(mapSize, 0, mapSize.Length);
            //gs.Write(levelData, 0, levelData.Length);

            int currentstart = 0;

            for (int i = 0; i < levelData.Length; i++ )
            {
                byte block = levelData[i];
                if(block>49)
                {
                    if(i>0) gs.Write(levelData, currentstart, (i-currentstart));
                    currentstart = i + 1;

                    gs.WriteByte((Block.Blocks.ContainsKey(block) ? Block.Blocks[block].BaseType : (byte)0));
                }

            }

            if (currentstart != levelData.Length)
            {
                gs.Write(levelData, currentstart, (levelData.Length - currentstart));
            }

            gs.Flush();
            gs.Dispose();

            ms.Position = 0;
            var bytes = new byte[ms.Length];
            ms.Read(bytes, 0, (int) ms.Length);
            ms.Close();
            ms.Dispose();
            return bytes;
        }
开发者ID:Merlin33069,项目名称:MineFrog,代码行数:37,代码来源:Player.cs

示例10: FullSave

        internal void FullSave()
        {
            /*
             * All we need to do here is dump our level blocks to the file
             *
             * we dont need to close the filehandle for the uncompressed version
             */

            Server.Log("Full Save Directory check...", LogTypesEnum.debug);
            DirectoryCheck();

            Server.Log("Backup old file...", LogTypesEnum.debug);
            if (File.Exists(fileName + compressedExtension))
            {
                if (File.Exists(fileName + compressedExtension + backupExtension)) File.Delete(fileName + compressedExtension + backupExtension);
                File.Copy(fileName + compressedExtension, fileName + compressedExtension + backupExtension);
            }

            Server.Log("Saving new File...", LogTypesEnum.debug);
            FileStream fileStream = new FileStream(compressedPath, FileMode.Create);
            GZipStream gzipStream = new GZipStream(fileStream, CompressionMode.Compress);

            gzipStream.Write(encode.GetBytes(name.PadRight(64)), 0, 64);
            gzipStream.Write(BitConverter.GetBytes(sizeX), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(sizeY), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(sizeZ), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(spawnPos.x), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(spawnPos.y), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(spawnPos.z), 0, 2);
            gzipStream.WriteByte(spawnPos.pitch);
            gzipStream.WriteByte(spawnPos.yaw);
            gzipStream.Write(BitConverter.GetBytes(physics.isEnabled), 0, 1);
            gzipStream.Write(BitConverter.GetBytes(physics.realistic), 0, 1);

            gzipStream.Write(blocks, 0, blocks.Length);

            gzipStream.Flush();
            gzipStream.Close();
            //fileStream.Flush();
            fileStream.Close();

            Console.WriteLine("Done?");
        }
开发者ID:MinedroidFTW,项目名称:MineFrog,代码行数:43,代码来源:Level.cs

示例11: Save

 public void Save(string outpath)
 {
     #if WIN32
     {
         string file = System.IO.Path.Combine(outpath, "seeds.bin.bytes");
         if (System.IO.Directory.Exists(outpath) == false)
         {
             System.IO.Directory.CreateDirectory(outpath);
         }
         using (System.IO.Stream os = System.IO.File.Create(file))
         {
     #if USECompression
             using (GZipStream s = new GZipStream(os, CompressionMode.Compress))
     #else
             var s = os;
     #endif
             {
                 UInt16 len=(UInt16) seeds.Count;
                 s.Write(BitConverter.GetBytes(len), 0, 2);
                 foreach (var i in seeds)
                 {
                     byte[] sb = System.Text.Encoding.UTF8.GetBytes(i.Key);
                     s.WriteByte((byte)sb.Length);
                     s.Write(sb, 0, sb.Length);
                     i.Value.Write(s);
                 }
             }
         }
     }
     string flist = "";
     foreach (var i in anims)
     {
         string file = System.IO.Path.Combine(outpath, i.Key + ".anim.bin");
         using (System.IO.Stream s = System.IO.File.Create(file+".bytes"))
         {
             i.Value.Write(s);
         }
         flist += file + "\r\n";
     }
     System.IO.File.WriteAllText(System.IO.Path.Combine(outpath, "anims.txt"), flist);
     #endif
 }
开发者ID:Gaopest,项目名称:fightclub,代码行数:42,代码来源:AniData.cs

示例12: Slice

        static void Slice(string sourceFile, string destinationDirectory, int parts)
        {
            int partsCounter = 0;
            int dotPosition = sourceFile.LastIndexOf('.');
            int slashPosition = sourceFile.LastIndexOf('\\');
            string sourceFileName = sourceFile.Substring(slashPosition + 1, dotPosition - slashPosition - 1);
            string sourceFileExtension = sourceFile.Substring(dotPosition);
            if (destinationDirectory.LastIndexOf('\\') != destinationDirectory.Length - 1)
            {
                destinationDirectory += "\\";
            }

            using (FileStream source = new FileStream(sourceFile, FileMode.Open, FileAccess.ReadWrite))
            {
                long partSize = source.Length / parts;
                while (partsCounter < parts)
                {
                    source.Position = partsCounter * partSize;
                    using (FileStream destination = new FileStream(destinationDirectory + sourceFileName + "-part" + partsCounter + sourceFileExtension + ".gz", FileMode.OpenOrCreate, FileAccess.Write))
                    {
                        using (GZipStream compressionStream = new GZipStream(destination,CompressionLevel.Optimal))
                        {
                            long byteCounter = 0;
                            while (byteCounter <= partSize)
                            {
                                compressionStream.WriteByte((byte)source.ReadByte());
                                byteCounter++;
                            }
                        }
                    }
                    partsCounter++;
                }
            }
            Console.WriteLine("The file was sliced successfully.");
        }
开发者ID:dkirilov,项目名称:homeworks,代码行数:35,代码来源:Problem6_ZippingSlicedFiles.cs

示例13: Main


//.........这里部分代码省略.........
                apiAccessHeader.APIAccessCode = API_ACCESS_CODE;
                obj.APIAccessHeaderValue = apiAccessHeader;
                b2b.wsdot.wa.gov.TripDateMsg tripDateMsg = new b2b.wsdot.wa.gov.TripDateMsg();
                b2b.wsdot.wa.gov.RouteMsg routeMsg = new b2b.wsdot.wa.gov.RouteMsg();

                tripDateMsg.TripDate = DateTime.Today;

                // Provide all available routes for a particular date.
                b2b.wsdot.wa.gov.RouteBriefResponse[] routes = obj.GetAllRoutes(tripDateMsg);

                for (int i=0; i<routes.Length; i++)
                {
                    _items.Add(new FerriesRoute() {
                        RouteID = routes[i].RouteID,
                        Description = routes[i].Description
                    });

                    DateTime today = DateTime.Today;

                    for (int j=0; j<7; j++)
                    {
                        _items[i].Date.Add(new Dates() {
                            Date = today
                        });

                        routeMsg.RouteID = routes[i].RouteID;
                        routeMsg.TripDate = today;

                        // Retrieve sailing times associated with a specific route for a particular date.
                        b2b.wsdot.wa.gov.SchedResponse scheduleByRouteResults = obj.GetScheduleByRoute(routeMsg);

                        for (int k=0; k<scheduleByRouteResults.TerminalCombos.Length; k++)
                        {
                            _items[i].Date[j].Sailings.Add(new FerriesTerminal() {
                                DepartingTerminalID = scheduleByRouteResults.TerminalCombos[k].DepartingTerminalID,
                                DepartingTerminalName = scheduleByRouteResults.TerminalCombos[k].DepartingTerminalName,
                                ArrivingTerminalID = scheduleByRouteResults.TerminalCombos[k].ArrivingTerminalID,
                                ArrivingTerminalName = scheduleByRouteResults.TerminalCombos[k].ArrivingTerminalName
                            });

                            b2b.wsdot.wa.gov.TerminalComboMsg terminalComboMsg = new b2b.wsdot.wa.gov.TerminalComboMsg();
                            terminalComboMsg.TripDate = today;
                            terminalComboMsg.DepartingTerminalID = scheduleByRouteResults.TerminalCombos[k].DepartingTerminalID;
                            terminalComboMsg.ArrivingTerminalID = scheduleByRouteResults.TerminalCombos[k].ArrivingTerminalID;

                            // Retrieve sailing times associated with a specific departing / arriving terminal combination for a particular date.
                            b2b.wsdot.wa.gov.SchedResponse scheduleByTerminalComboResults = obj.GetScheduleByTerminalCombo(terminalComboMsg);

                            for (int l=0; l<scheduleByTerminalComboResults.TerminalCombos.Length; l++)
                            {
                                for (int m=0; m<scheduleByTerminalComboResults.TerminalCombos[l].Annotations.Length; m++)
                                {
                                    _items[i].Date[j].Sailings[k].Annotations.Add(scheduleByTerminalComboResults.TerminalCombos[l].Annotations[m]);
                                }

                                for (int n=0; n<scheduleByTerminalComboResults.TerminalCombos[l].Times.Length; n++)
                                {
                                    _items[i].Date[j].Sailings[k].Times.Add(new FerriesScheduleTimes() {
                                        DepartingTime = scheduleByTerminalComboResults.TerminalCombos[l].Times[n].DepartingTime
                                    });

                                    for (int o=0; o<scheduleByTerminalComboResults.TerminalCombos[l].Times[n].AnnotationIndexes.Length; o++)
                                    {
                                        _items[i].Date[j].Sailings[k].Times[n].AnnotationIndexes.Add(scheduleByTerminalComboResults.TerminalCombos[l].Times[n].AnnotationIndexes[o]);
                                    }
                                }
                            }
                        }

                        today = today.AddDays(1);
                    }

                }

                // Serialize the data object to a JSON file.
                string json = JsonConvert.SerializeObject(_items);
                File.WriteAllText(@"WSFRouteSchedules.js", json);

                FileStream sourceFile = File.OpenRead(@"WSFRouteSchedules.js");
                FileStream destFile = File.Create(@"WSFRouteSchedules.js.gz");

                // Now compress the JSON file so it is smaller to download.
                // Uncompressed the file is about 459 KB, compressed it drops to 25 KB. Nice.
                GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);

                try
                {
                    int theByte = sourceFile.ReadByte();
                    while (theByte != -1)
                    {
                        compStream.WriteByte((byte)theByte);
                        theByte = sourceFile.ReadByte();
                    }
                }
                finally
                {
                    compStream.Dispose();
                }
            }
        }
开发者ID:rgordon,项目名称:WSFRouteSchedules,代码行数:101,代码来源:Main.cs

示例14: FullSave

        public void FullSave()
        {
            /*
             * All we need to do here is dump our level blocks to the file
             *
             * we dont need to close the filehandle for the uncompressed version
             */

            Server.Log("Full Save Directory check...", LogTypesEnum.Debug);
            DirectoryCheck();

            Server.Log("Backup old file...", LogTypesEnum.Debug);
            if (File.Exists(FileName + CompressedExtension))
            {
                if (File.Exists(FileName + CompressedExtension + BackupExtension))
                    File.Delete(FileName + CompressedExtension + BackupExtension);
                File.Copy(FileName + CompressedExtension, FileName + CompressedExtension + BackupExtension);
            }

            Server.Log("Saving new File...", LogTypesEnum.Debug);
            var fileStream = new FileStream(CompressedPath, FileMode.Create);
            var gzipStream = new GZipStream(fileStream, CompressionMode.Compress);

            gzipStream.Write(_encode.GetBytes(Name.PadRight(64)), 0, 64);
            gzipStream.Write(BitConverter.GetBytes(SizeX), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(SizeY), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(SizeZ), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(SpawnPos.X), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(SpawnPos.Y), 0, 2);
            gzipStream.Write(BitConverter.GetBytes(SpawnPos.Z), 0, 2);
            gzipStream.WriteByte(SpawnPos.Pitch);
            gzipStream.WriteByte(SpawnPos.Yaw);
            gzipStream.Write(BitConverter.GetBytes(Physics.IsEnabled), 0, 1);
            gzipStream.Write(BitConverter.GetBytes(Physics.Realistic), 0, 1);
            gzipStream.WriteByte(BuildPermissions);
            gzipStream.WriteByte(VisitPermissions);

            gzipStream.Write(BlockData, 0, BlockData.Length);

            gzipStream.Flush();
            gzipStream.Close();
            //fileStream.Flush();
            fileStream.Close();

            Console.WriteLine("Done?");
        }
开发者ID:ninedrafted,项目名称:MineFrog,代码行数:46,代码来源:Level.cs

示例15: Save

        public static void Save(VoxelSprite sprite, ref Color[] swatches)
        {
            //StringBuilder sb = new StringBuilder();

            //using (StringWriter str = new StringWriter(sb))
            //{

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.AddExtension = true;
            sfd.DefaultExt = ".vxl";
            sfd.Filter = "Voxel Sprite|*.vxs";
            DialogResult dr = sfd.ShowDialog();

            if (string.IsNullOrEmpty(sfd.FileName) || dr != DialogResult.OK) return;

            using (FileStream str = new FileStream(sfd.FileName, FileMode.Create))
            {
                //str.Write(gameWorld.X_CHUNKS + "," + gameWorld.Y_CHUNKS + "," + gameWorld.Z_CHUNKS + "\n");
                using (GZipStream gzstr = new GZipStream(str, CompressionMode.Compress))
                {

                    gzstr.WriteByte(Convert.ToByte(sprite.X_SIZE));
                    gzstr.WriteByte(Convert.ToByte(sprite.Y_SIZE));
                    gzstr.WriteByte(Convert.ToByte(sprite.Z_SIZE));
                    gzstr.WriteByte(Convert.ToByte(sprite.AnimChunks.Count));

                    for (int i = 0; i < 10; i++)
                    {
                        gzstr.WriteByte(swatches[i].R);
                        gzstr.WriteByte(swatches[i].G);
                        gzstr.WriteByte(swatches[i].B);
                    }

                    foreach (AnimChunk c in sprite.AnimChunks)
                    {
                        //str.Write("C\n");

                        //Chunk c = gameWorld.Chunks[x, y, z];
                        for (int vx = 0; vx < sprite.X_SIZE; vx++)
                            for (int vy = 0; vy < sprite.Y_SIZE; vy++)
                                for (int vz = 0; vz < sprite.Z_SIZE; vz++)
                                {
                                    if (!c.Voxels[vx, vy, vz].Active) continue;

                                    //string vox = vx + "," + vy + "," + vz + ",";
                                    //vox += ((int)c.Voxels[vx, vy, vz].Type);
                                    //str.Write(vox + "\n");

                                    gzstr.WriteByte(Convert.ToByte(vx));
                                    gzstr.WriteByte(Convert.ToByte(vy));
                                    gzstr.WriteByte(Convert.ToByte(vz));
                                    gzstr.WriteByte(c.Voxels[vx, vy, vz].Color.R);
                                    gzstr.WriteByte(c.Voxels[vx, vy, vz].Color.G);
                                    gzstr.WriteByte(c.Voxels[vx, vy, vz].Color.B);
                                }
                        gzstr.WriteByte(Convert.ToByte('c'));

                    }
                    //str.Flush();

                }
            }
            //}

            //using (StreamWriter fs = new StreamWriter(fn))
            //{
            //    fs.Write(Compress(sb.ToString()));
            //    fs.Flush();
            //}

            //sb.Clear();
            //sb = null;

            GC.Collect();
        }
开发者ID:GarethIW,项目名称:VoxelLandscapeEditor,代码行数:75,代码来源:LoadSave.cs


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