Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 16th, 2012  |  syntax: None  |  size: 2.39 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Create new FileStream out of a byte array
  2. FolderBrowserDialog fbd = new FolderBrowserDialog(); // Shows a browser dialog
  3.  fbd.ShowDialog();
  4.  
  5.             // Path to directory of files to compress and decompress.
  6.             string dirpath = fbd.SelectedPath;
  7.  
  8.             DirectoryInfo di = new DirectoryInfo(dirpath);
  9.  
  10.  
  11.  foreach (FileInfo fi in di.GetFiles())
  12.             {
  13.                 zip.Program.Decompress(fi);
  14.  
  15.             }
  16.  
  17.             // Get the stream of the source file.
  18.             using (FileStream inFile = fi.OpenRead())
  19.             {
  20.  
  21.                 //Create the decompressed file.
  22.                 string outfile = @"C:Decompressed.exe";
  23.                 {
  24.                     using (GZipStream Decompress = new GZipStream(inFile,
  25.                             CompressionMode.Decompress))
  26.                     {
  27.                         byte[] b = new byte[blen.Length];
  28.                         Decompress.Read(b,0,b.Length);
  29.                         File.WriteAllBytes(outfile, b);
  30.                     }
  31.                 }
  32.             }
  33.        
  34. const int BufferSize = 65536;
  35. byte[] compressedBytes = File.ReadAllBytes("compressedFilename");
  36. // create memory stream
  37. using (var mstrm = new MemoryStream(compressedBytes))
  38. {
  39.     using(var inStream = new GzipStream(mstrm, CompressionMode.Decompress))
  40.     {
  41.         using (var outStream = File.Create("outputfilename"))
  42.         {
  43.             var buffer = new byte[BufferSize];
  44.             int bytesRead;
  45.             while ((bytesRead = inStream.Read(buffer, 0, BufferSize)) != 0)
  46.             {
  47.                 outStream.Write(buffer, 0, bytesRead);
  48.             }  
  49.         }
  50.     }
  51. }
  52.        
  53. string fi = @"C:Path To Compressed File";
  54.     // Get the stream of the source file.
  55.            //     using (FileStream inFile = fi.OpenRead())
  56.                 using (MemoryStream infile1 = new MemoryStream(File.ReadAllBytes(fi)))
  57.                 {
  58.  
  59.                     //Create the decompressed file.
  60.                     string outfile = @"C:Decompressed.exe";
  61.                     {
  62.                         using (GZipStream Decompress = new GZipStream(infile1,
  63.                                 CompressionMode.Decompress))
  64.                         {
  65.                             byte[] b = new byte[blen.Length];
  66.                             Decompress.Read(b,0,b.Length);
  67.                             File.WriteAllBytes(outfile, b);
  68.                         }
  69.                     }
  70.                 }