Create new FileStream out of a byte array

前端 未结 3 1952
忘掉有多难
忘掉有多难 2021-01-13 19:04

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.

Tasks I am

3条回答
  •  暖寄归人
    2021-01-13 20:03

    Here is what I ended up doing. I realize that I did not give sufficient information in my question - and I apologize for that - but I do know the size of the file I need to decompress as I am using it earlier in my program. This buffer is referred to as "blen".

    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);
                            }
                        }
                    }
    

提交回复
热议问题