我有此代码:
using (FileStream sourceStream = new FileStream(sourceFile, FileMode.OpenOrCreate))
{
using (FileStream targetStream = File.Create(compressedFile))
{
using (GZipStream compressionStream = new GZipStream(targetStream, CompressionMode.Compress))
{
sourceStream.CopyTo(compressionStream);
Console.WriteLine(
"Compress of file{0} is end. Inintial size: {1} compressed size: {2}.",
sourceFile,
sourceStream.Length.ToString(),
targetStream.Length.ToString());
}
}
}
现在,我需要异步编写compressiong文件的进度。我该怎么办?
答案 0 :(得分:0)
首先找到源文件的大小。然后,进度是到目前为止消耗的源文件中的输入字节数除以源文件的大小。