public byte[] Decompress(byte[] input) { if (input == null) { throw new ArgumentNullException("input"); } var output = new List <byte>(); using (var ms = new MemoryStream(input)) { var gs = new GZipStream(ms, CompressionMode.Decompress); var readByte = gs.ReadByte(); while (readByte != -1) { output.Add((byte)readByte); readByte = gs.ReadByte(); } gs.Close(); ms.Close(); } return(output.ToArray()); }
static void Main(string[] args) { string inFilename = @"c:\ttt.txt"; string outFilename = @"c:\ttt.txt.gz"; //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(); //} //compStream.Close(); string inFilename1 = @"c:\tttt.txt"; FileStream sourceFile = File.OpenRead(outFilename); FileStream destFile = File.Create(inFilename1); GZipStream compStream = new GZipStream(sourceFile, CompressionMode.Decompress); int theByte = compStream.ReadByte(); while (theByte != -1) { destFile.WriteByte((byte)theByte); theByte = compStream.ReadByte(); } compStream.Close(); }
/// <summary> /// Descomprimir un archivo /// </summary> /// <param name="Origen">Ruta física del archivo a descomprimir</param> /// <param name="Destino">Nueva ruta física del archivo descomprimido</param> public void DesComprimirGZIP(string Origen, string Destino) { try { using (FileStream FsOrigen = File.OpenRead(Origen)) { using (FileStream FsDestino = new FileStream(Destino, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (GZipStream FsComprimir = new GZipStream(FsOrigen, CompressionMode.Decompress)) { int bData = FsComprimir.ReadByte(); while (bData != -1) { //Escribe un byte en la posicion actual FsDestino.WriteByte((byte)bData); bData = FsComprimir.ReadByte(); } FsComprimir.Close(); } FsDestino.Close(); } FsOrigen.Close(); } } catch (Exception) { throw; } }
public static void UncompressFile(string inFilename, string outFilename) { try { var sourceFile = File.Open(inFilename, FileMode.Open); var destFile = File.Create(outFilename); var compStream = new GZipStream(sourceFile, CompressionMode.Decompress); var theByte = compStream.ReadByte(); while (theByte != -1) { destFile.WriteByte((byte)theByte); theByte = compStream.ReadByte(); } compStream.Close(); sourceFile.Close(); destFile.Close(); Console.WriteLine($"\"{inFilename}\" разархивирован в \"{outFilename}\"."); } catch (Exception ex) { Console.WriteLine($"Произошла ошибка: {ex.Message}"); } }
//Descomprimir archivo gz,zip,etc public void descomprimir(string ruta, string archivo_descomprimido) { try{ using (FileStream fs = new FileStream(ruta, FileMode.Open, FileAccess.Read)) { using (FileStream fsd = new FileStream(archivo_descomprimido, FileMode.OpenOrCreate, FileAccess.Write)) { using (GZipStream gs = new GZipStream(fs, CompressionMode.Decompress)) { int i = gs.ReadByte(); while (i != -1) { fsd.WriteByte((byte)i); i = gs.ReadByte(); } gs.Close(); } fsd.Close(); } fs.Close(); } } catch (Exception excepccion) { System.Windows.MessageBox.Show("Error, consulte a su Administrador de Sistema"); } }
/// <summary> /// Decompresses the specified compressed bytes. /// </summary> /// <param name="compressed">The compressed.</param> /// <returns>A byte array with the decompressed content</returns> public static byte[] Decompress(this byte[] compressedbytes) { byte[] decompressed = null; using (MemoryStream writer = new MemoryStream(compressedbytes, true)) { using (GZipStream input = new GZipStream(writer, CompressionMode.Decompress)) { using (MemoryStream output = new MemoryStream()) { int currentValue = input.ReadByte(); if (currentValue == -1) { ///Marcel Valdez: ///Cuando no se termina correctamente el GZipStream, el primer valor es un -1 ///indicando que no se terminó de leer, para esto se intentará recuperar los ///datos del GZipStream con la información recibida. currentValue = input.ReadByte(); } while (currentValue != -1) { output.WriteByte((byte)(currentValue & 0xFF)); currentValue = input.ReadByte(); } decompressed = output.ToArray(); } } } return(decompressed); }
private void buttonDecompress_Click(object sender, EventArgs e) { FileStream sourceFile = File.OpenRead(@"C:\TEST\MCTS(rgb)_512.gz"); FileStream destFile = File.Create(@"C:\TEST\New\MCTS(rgb)_512.jpg"); gzip = new GZipStream(sourceFile, CompressionMode.Decompress, true); int theByte = gzip.ReadByte(); while (theByte != -1) { destFile.WriteByte((byte)theByte); theByte = gzip.ReadByte(); } gzip.Flush(); gzip.Close(); gzip.Dispose(); destFile.Close(); destFile.Dispose(); sourceFile.Close(); sourceFile.Dispose(); MessageBox.Show("Done"); }
private void Form1_Load(object sender, EventArgs e) { ass = Assembly.GetExecutingAssembly(); string[] res = ass.GetManifestResourceNames(); try { string name = "bjArkiv.xml.gz"; Stream rs = ass.GetManifestResourceStream(name); using (Stream gzip = new GZipStream(rs, CompressionMode.Decompress, true)) { using (MemoryStream menfile = new MemoryStream()) { for (int b = gzip.ReadByte(); b != -1; b = gzip.ReadByte()) { menfile.WriteByte((byte)b); } db = xmldocs.Load(menfile); xmldocsBindingSource.DataSource = db; } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, ass.GetName().Name, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static string Descomprimir(FileStream fs) { byte[] datosSalida = new byte[0]; try { GZipStream decompressedZipStream = new GZipStream(fs, CompressionMode.Decompress); List <byte> listdatosSalida = new List <byte>(); ASCIIEncoding oASCIIEncoding = new ASCIIEncoding(); string base64String = ""; for (int read = decompressedZipStream.ReadByte(); read != -1; read = decompressedZipStream.ReadByte()) { listdatosSalida.Add((byte)read); base64String = oASCIIEncoding.GetString(listdatosSalida.ToArray()); } //datosSalida = new byte[10000]; //int nroOfBytes = decompressedZipStream.Read(datosSalida, 0, datosSalida.Length); //base64String = oASCIIEncoding.GetString(datosSalida); // Close the stream. decompressedZipStream.Close(); return(base64String); } catch (Exception ex) { string verQhagoConEsto = ex.Message; return(null); } }
//解壓縮 protected void Decompress() { //被壓縮後的檔案 FileStream sourceFile = File.OpenRead(@"C:\sample.gz"); //解壓縮後的檔案 FileStream destFile = File.Create(@"C:\Unsample.xml"); //開始 GZipStream compStream = new GZipStream(sourceFile, CompressionMode.Decompress, true); try { int theByte = compStream.ReadByte(); while (theByte != -1) { destFile.WriteByte((byte)theByte); theByte = compStream.ReadByte(); } } finally { compStream.Flush(); compStream.Dispose(); sourceFile.Flush(); sourceFile.Dispose(); destFile.Flush(); destFile.Dispose(); } }
public override Map Load(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.OpenRead(fileName)) { using (GZipStream gs = new GZipStream(mapStream, CompressionMode.Decompress)) { Map map = LoadHeaderInternal(gs); map.Blocks = new byte[map.Volume]; int i = 0, id; while ((id = gs.ReadByte()) != -1) { gs.ReadByte(); // NOTE: This breaks the 5 block ids past 255, but I doubt they really had much use. if (id <= (byte)Block.StoneBrick) { map.Blocks[i] = (byte)id; } else { map.Blocks[i] = Mapping[id]; } i++; } return(map); } } }
public static void Decompress(string sourceFileName, string destFileName) { try { //被壓縮後的檔案 FileStream sourceFile = File.OpenRead(sourceFileName); //解壓縮後的檔案 FileStream destFile = File.Create(destFileName); //開始 GZipStream compStream = new GZipStream(sourceFile, CompressionMode.Decompress, true); try { int theByte = compStream.ReadByte(); while (theByte != -1) { destFile.WriteByte((byte)theByte); theByte = compStream.ReadByte(); } } finally { compStream.Flush(); compStream.Dispose(); sourceFile.Flush(); sourceFile.Dispose(); destFile.Flush(); destFile.Dispose(); } } catch { } }
public HttpWebResponse GetData(HttpWebRequest httpWebRequest, out string responseText) { ServicePointManager.Expect100Continue = false; //Resolve http 417 issue HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Encoding encoding = GetEncoding(httpWebResponse.ContentType); using (Stream outStream = httpWebResponse.GetResponseStream()) { string contentEncoding = httpWebResponse.ContentEncoding; if (contentEncoding.StartsWith("gzip")) { MemoryStream ms = new MemoryStream(); using (Stream stream = new GZipStream(outStream, CompressionMode.Decompress)) { int bit = stream.ReadByte(); while (bit > -1) { ms.WriteByte((byte)bit); bit = stream.ReadByte(); } responseText = encoding.GetString(ms.ToArray()); } } else if (contentEncoding.StartsWith("deflate")) { MemoryStream ms = new MemoryStream(); using (Stream stream = new DeflateStream(outStream, CompressionMode.Decompress)) { int bit = stream.ReadByte(); while (bit > -1) { ms.WriteByte((byte)bit); bit = stream.ReadByte(); } responseText = encoding.GetString(ms.ToArray()); } } else { using (StreamReader sr = new StreamReader(outStream, encoding)) { responseText = sr.ReadToEnd(); } } } return(httpWebResponse); }
public static Level Load(string name, string file) { using (Stream fs = File.OpenRead(file), gs = new GZipStream(fs, CompressionMode.Decompress, true)) { byte[] header = new byte[16]; gs.Read(header, 0, 2); ushort[] vars = new ushort[6]; vars[0] = BitConverter.ToUInt16(header, 0); int offset = 0; if (vars[0] == 1874) // version field, width is next ushort { gs.Read(header, 0, 16); vars[0] = BitConverter.ToUInt16(header, 0); offset = 2; } else { gs.Read(header, 0, 12); } vars[1] = BitConverter.ToUInt16(header, offset); vars[2] = BitConverter.ToUInt16(header, offset + 2); Level level = new Level(name, vars[0], vars[2], vars[1]); level.spawnx = BitConverter.ToUInt16(header, offset + 4); level.spawnz = BitConverter.ToUInt16(header, offset + 6); level.spawny = BitConverter.ToUInt16(header, offset + 8); level.rotx = header[offset + 10]; level.roty = header[offset + 11]; gs.Read(level.blocks, 0, level.blocks.Length); if (gs.ReadByte() != 0xBD) { return(level); } 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++) { if (gs.ReadByte() == 1) { byte[] chunk = new byte[16 * 16 * 16]; gs.Read(chunk, 0, chunk.Length); level.CustomBlocks[index] = chunk; } index++; } } } return(level); } }
/// <summary> /// Wraps the given stream in a decompression stream. /// </summary> /// <param name="input">Stream to wrap.</param> /// <returns>Decompression stream from which decompressed data can be read.</returns> public static Stream DecompressStream(Stream input) { Stream result = new GZipStream(input, CompressionMode.Decompress); int magic = result.ReadByte() << 24 | result.ReadByte() << 16 | result.ReadByte() << 8 | result.ReadByte(); if (magic != MagicNumber) { throw new Exception("Unsupported compression scheme or bad magic number."); } return(result); }
static void UncompressFile(string inFilename, string outFilename) { FileStream sourceFile = File.OpenRead(inFilename); FileStream destFile = File.Create(outFilename); GZipStream compStream = new GZipStream(sourceFile, CompressionMode.Decompress); int theByte = compStream.ReadByte(); while (theByte != -1) { destFile.WriteByte((byte)theByte); theByte = compStream.ReadByte(); } compStream.Close(); }
public static void Decompress(Stream inStream, Stream outStream) { using (outStream) { using (GZipStream zipStream = new GZipStream(inStream, CompressionMode.Decompress)) { int ch = zipStream.ReadByte(); while (ch != -1) { outStream.WriteByte((byte)ch); ch = zipStream.ReadByte(); } } } }
public bool Load(string filename) { try { this.filename = filename; GZipStream gzin = new GZipStream(new FileStream("maps/" + filename, FileMode.Open), CompressionMode.Decompress); byte[] magicnumbytes = new byte[4]; gzin.Read(magicnumbytes, 0, 4); if (!(BitConverter.ToUInt32(magicnumbytes, 0) == 0xebabefac)) { Program.server.logger.log("Wrong magic number in level file: " + BitConverter.ToUInt32(magicnumbytes, 0), Logger.LogType.Error); return(false); } byte[] leveldimensions = new byte[6]; gzin.Read(leveldimensions, 0, 6); this.width = BitConverter.ToInt16(leveldimensions, 0); this.height = BitConverter.ToInt16(leveldimensions, 2); this.depth = BitConverter.ToInt16(leveldimensions, 4); byte[] spawnpoint = new byte[6]; gzin.Read(spawnpoint, 0, 6); this.spawnx = BitConverter.ToInt16(spawnpoint, 0); this.spawny = BitConverter.ToInt16(spawnpoint, 2); this.spawnz = BitConverter.ToInt16(spawnpoint, 4); this.srotx = (byte)gzin.ReadByte(); this.sroty = (byte)gzin.ReadByte(); this.blocks = new byte[this.width * this.height * this.depth]; gzin.Read(blocks, 0, this.width * this.height * this.depth); //gzin.BaseStream.Close(); gzin.Close(); this.name = filename.Substring(0, filename.IndexOf(".umw")); Program.server.logger.log("Loaded world from " + filename); return(true); } catch (Exception e) { Program.server.logger.log("Error occurred while loading map", Logger.LogType.Error); Program.server.logger.log(e); return(false); } }
public void TestSave() { String filename = @"..\..\..\LibNBT Tests\Data\bigtest.nbt"; TagCompound tag = TagCompound.ReadFromFile(filename) as TagCompound; MemoryStream ms = new MemoryStream(); MemoryStream ms2; FileStream fs = File.OpenRead(filename); GZipStream gzStream = new GZipStream(fs, CompressionMode.Decompress); tag.Write(ms); ms2 = new MemoryStream((int)ms.Length); byte[] buffer = new byte[ms.Length]; Assert.AreEqual <long>(ms.Length, gzStream.Read(buffer, 0, (int)ms.Length)); Assert.AreEqual <int>(-1, gzStream.ReadByte()); byte[] buffer2 = ms.GetBuffer(); FileStream fs2 = File.OpenWrite(@"..\..\..\LibNBT Tests\Data\savetest.raw"); fs2.Write(buffer2, 0, (int)ms.Length); for (long i = 0; i < ms.Length; i++) { Assert.AreEqual <byte>(buffer[i], buffer2[i]); } }
public static void UnZip() { FileStream sourse = File.OpenRead(@"D:\archive.zip"); FileStream destination = File.Create(@"D:\text_zip.txt"); GZipStream decompressor = new GZipStream(sourse, CompressionMode.Decompress); int theByte = decompressor.ReadByte(); while (theByte != -1) { destination.WriteByte((byte)theByte); theByte = decompressor.ReadByte(); } decompressor.Close(); }
public virtual Map Load(string fileName) { if (fileName == null) { throw new ArgumentNullException("fileName"); } using (FileStream mapStream = File.OpenRead(fileName)) { using (GZipStream gs = new GZipStream(mapStream, CompressionMode.Decompress)) { Map map = LoadHeaderInternal(gs); // Read in the map data map.Blocks = new byte[map.Volume]; BufferUtil.ReadAll(gs, map.Blocks); map.ConvertBlockTypes(Mapping); if (gs.ReadByte() != 0xBD) { return(map); } ReadCustomBlocks(gs, map); return(map); } } }
public void loadWorldMap(Stream map) { GZipStream gz = new GZipStream(map, CompressionMode.Decompress); var areas = new List <KnyttArea>(); // Area definition starts with an 'x' character while (gz.ReadByte() == 'x') { var area = new KnyttArea(gz, this); areas.Add(area); this.MinBounds = this.MinBounds.min(area.Position); this.MaxBounds = this.MaxBounds.max(area.Position); } // Set the map this.Size = new KnyttPoint((MaxBounds.x - MinBounds.x) + 1, (MaxBounds.y - MinBounds.y) + 1); this.Map = new KnyttArea[this.Size.Area]; foreach (var area in areas) { this.Map[getMapIndex(area.Position)] = area; } }
public static byte[] Decompress(byte[] source) { if (source == null) { return(null); } if (source.Length < 2) { return(source); } List <byte> result = new List <byte>(); using (MemoryStream stream = new MemoryStream(source)) { using (GZipStream zip = new GZipStream(stream, CompressionMode.Decompress)) { int bValue = 0; while (true) { bValue = zip.ReadByte(); if (bValue == -1) { break; } else { result.Add((byte)bValue); } } } } return(result.ToArray()); }
static void Main(string[] args) { FileStream archiveStream = File.OpenRead(@"D:\archive_zip.zip"); FileStream destinationStream = File.Create(@"D:\txt_destnation_zip.txt"); GZipStream deCompressor = new GZipStream(archiveStream, CompressionMode.Decompress); //В прошлых примерах цикл бы неправильный! нужно do - while do { var theByte = deCompressor.ReadByte(); if (theByte == -1) { break; } destinationStream.WriteByte((byte)theByte); }while (true); //появлялось"я" в файле, потому, что оно записывало -1. пришлось сделать do - while (true) и выход из цикла. //int theByte = deCompressor.ReadByte(); //while (theByte != -1) //{ // destinationStream.WriteByte((byte)theByte); // theByte = deCompressor.ReadByte(); //} deCompressor.Close(); destinationStream.Close(); }
public static SqlBytes xfnGUnzip(SqlBytes data) { SqlBytes result; using (MemoryStream memoryStream = new MemoryStream(data.Value)) using (GZipStream gZipStream = new GZipStream(memoryStream, CompressionMode.Decompress)) using (MemoryStream memoryStream2 = new MemoryStream()) { for (int num = gZipStream.ReadByte(); num != -1; num = gZipStream.ReadByte()) { memoryStream2.WriteByte((byte)num); } result = new SqlBytes(memoryStream2.ToArray()); } return(result); }
public static void FillCharMap(string CharMapPath) { var charProperties = new List <CharacterProperty>(); bool broken = false; using (FileStream originalFileStream = File.Open(CharMapPath, FileMode.Open)) { using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) { while (true) { var bX = new byte[sizeof(float)]; if (decompressionStream.Read(bX, 0, sizeof(float)) == 0) { broken = true; break; } var bCharWrapping = decompressionStream.ReadByte() == 0x01; charProperties.Add(new CharacterProperty(BitConverter.ToSingle(bX, 0), bCharWrapping)); } } } CharacterProperties = charProperties.ToArray(); Debug.Assert(broken); Debug.Assert(CharacterProperties['A'].Width == 8); Debug.Assert(CharacterProperties['@'].Width == 12.171875f); }
/// <summary> /// Decompresses the given byte array /// </summary> public byte[] Decompress(byte[] input) { using (var output = new MemoryStream(input)) { using (var zip = new GZipStream(output, CompressionMode.Decompress)) { var bytes = new List <byte>(); var b = zip.ReadByte(); while (b != -1) { bytes.Add((byte)b); b = zip.ReadByte(); } return(bytes.ToArray()); } } }
public void DeCompress(string openPath, string createPath) { var source = File.OpenRead(openPath); var destination = File.Create(createPath); var deCompressor = new GZipStream(source, CompressionMode.Decompress); int theByte = deCompressor.ReadByte(); while (theByte != -1) { destination.WriteByte((byte)theByte); theByte = deCompressor.ReadByte(); } destination.Close(); deCompressor.Close(); source.Close(); }
//static void CompressFile(string inFileName, string outFileName) //{ //} //static void UncompressFile(string inFileName, string outFileName) //{ //} static void Main(string[] args) { string inFileName = @"C:\Users\laik1\source\repos\dima4553\NewRepo\Praktika 2\Практикум 3\123.txt"; string outFileName = @"C:\Users\laik1\source\repos\dima4553\NewRepo\Praktika 2\Практикум 3\123.txt.gz"; string inFileName1 = @"C:\Users\laik1\source\repos\dima4553\NewRepo\Praktika 2\Практикум 3\1234.txt"; FileStream sourceFile = File.OpenRead(outFileName); FileStream destFile = File.Create(inFileName1); GZipStream compStream = new GZipStream(sourceFile, CompressionMode.Decompress); int theByte = compStream.ReadByte(); while (theByte != -1) { destFile.WriteByte((byte)theByte); theByte = compStream.ReadByte(); } compStream.Close(); }
private void btnConn_Click(object sender, EventArgs e) { Client = new TcpClient(); try { Client.Connect(new IPEndPoint(IPAddress.Parse(txtEndereco.Text), 1432)); } catch { MessageBox.Show(this, "Conexão recusada", "Screen Share", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } txtEndereco.Enabled = btnConn.Enabled = false; Task.Run(() => { using (Stream stream = new GZipStream(Client.GetStream(), CompressionMode.Decompress)) { try { using (BinaryReader reader = new BinaryReader(stream)) { while (stream.ReadByte() == 1) { Image img; byte[] bytes = reader.ReadBytes(reader.ReadInt32()); using (MemoryStream ms = new MemoryStream(bytes)) img = Image.FromStream(ms); Invoke((MethodInvoker)(() => { if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = img; })); } } } catch (Exception ex) { Invoke((MethodInvoker)(() => MessageBox.Show(this, "Conexão perdida (" + ex.Message + ")", "Screen Share", MessageBoxButtons.OK, MessageBoxIcon.Error))); } } Invoke((MethodInvoker)(() => { pictureBox1.Image = pictureBox1.ErrorImage; txtEndereco.Enabled = btnConn.Enabled = true; })); }); }