Exemplo n.º 1
0
        /// <summary>An async alternative to the <see cref="ZipArchiveEntry.ExtractToFile"/> extension method, using asynchronous IO.</summary>
        /// <remarks>The <b>overwrite</b> parameter was added to be consistent with <b>ZipArchiveEntry.ExtractToFile</b>, although my own
        /// preference is always to overwrite; hence my <b>ExtractEntriesToDirectoryAsync</b> implementation defaults to passing <b>true</b>.</remarks>
        public static async Task ExtractToFileAsync(this ZipArchiveEntry source, string destinationFileName, bool overwrite)
        {
            if (overwrite || !File.Exists(destinationFileName))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(destinationFileName));

                using (var destStream = new FileStream(destinationFileName, FileMode.Create, FileAccess.Write, FileShare.None, XBRLConstants.LargeBufferSize, true))
                {
                    await source.ExtractToStreamAsync(destStream);
                }
                File.SetLastWriteTime(destinationFileName, source.LastWriteTime.DateTime);
            }
        }