- Create new FileStream out of a byte array
- FolderBrowserDialog fbd = new FolderBrowserDialog(); // Shows a browser dialog
- fbd.ShowDialog();
- // Path to directory of files to compress and decompress.
- string dirpath = fbd.SelectedPath;
- DirectoryInfo di = new DirectoryInfo(dirpath);
- foreach (FileInfo fi in di.GetFiles())
- {
- zip.Program.Decompress(fi);
- }
- // Get the stream of the source file.
- using (FileStream inFile = fi.OpenRead())
- {
- //Create the decompressed file.
- string outfile = @"C:Decompressed.exe";
- {
- using (GZipStream Decompress = new GZipStream(inFile,
- CompressionMode.Decompress))
- {
- byte[] b = new byte[blen.Length];
- Decompress.Read(b,0,b.Length);
- File.WriteAllBytes(outfile, b);
- }
- }
- }
- const int BufferSize = 65536;
- byte[] compressedBytes = File.ReadAllBytes("compressedFilename");
- // create memory stream
- using (var mstrm = new MemoryStream(compressedBytes))
- {
- using(var inStream = new GzipStream(mstrm, CompressionMode.Decompress))
- {
- using (var outStream = File.Create("outputfilename"))
- {
- var buffer = new byte[BufferSize];
- int bytesRead;
- while ((bytesRead = inStream.Read(buffer, 0, BufferSize)) != 0)
- {
- outStream.Write(buffer, 0, bytesRead);
- }
- }
- }
- }
- string fi = @"C:Path To Compressed File";
- // Get the stream of the source file.
- // using (FileStream inFile = fi.OpenRead())
- using (MemoryStream infile1 = new MemoryStream(File.ReadAllBytes(fi)))
- {
- //Create the decompressed file.
- string outfile = @"C:Decompressed.exe";
- {
- using (GZipStream Decompress = new GZipStream(infile1,
- CompressionMode.Decompress))
- {
- byte[] b = new byte[blen.Length];
- Decompress.Read(b,0,b.Length);
- File.WriteAllBytes(outfile, b);
- }
- }
- }