我试图从字节数组创建一个新的FileStream对象.我确信根本没有任何意义,所以我将在下面进一步详细解释.
我正在完成的任务:1)读取先前压缩的源文件 2)使用GZipStream解压缩数据3)将解压缩的数据复制到字节数组中.
我想改变什么:
1)我希望能够使用File.ReadAllBytes来读取解压缩的数据.2)然后我想使用这个字节数组创建一个新的文件流对象.
简而言之,我想使用字节数组完成整个操作.GZipStream的一个参数是某种类型的流,所以我认为我使用了一个文件流.但是,如果存在某些方法,我可以从字节数组创建一个新的FileStream实例 - 那么我应该没问题.
这是我到目前为止:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!此致,埃文