Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate new FileStream out of a byte array
    text
    copied!<p>I am attempting to create a new FileStream object from a byte array. I'm sure that made no sense at all so I will try to explain in further detail below.</p> <p>Tasks I am completing: 1) Reading the source file which was previously <em>compressed</em> 2) Decompressing the data using GZipStream 3) copying the decompressed data into a byte array.</p> <p><strong>What I would like to change:</strong></p> <p>1) I would like to be able to use File.ReadAllBytes to read the decompressed data. 2) I would then like to create a new filestream object usingg this byte array.</p> <p>In short, I want to do this entire operating using byte arrays. One of the parameters for GZipStream is a stream of some sort, so I figured I was stuck using a filestream. But, if some method exists where I can create a new instance of a FileStream from a byte array - then I should be fine.</p> <p>Here is what I have so far:</p> <pre><code>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); } } } </code></pre> <p>Thanks for any help! Regards, Evan</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload