@@ -477,7 +477,8 @@ public DevToolsSession GetDevToolsSession(int protocolVersion)
477477 public IReadOnlyList < string > GetDownloadableFiles ( )
478478 {
479479 var enableDownloads = this . Capabilities . GetCapability ( CapabilityType . EnableDownloads ) ;
480- if ( enableDownloads == null || ! ( bool ) enableDownloads ) {
480+ if ( enableDownloads == null || ! ( bool ) enableDownloads )
481+ {
481482 throw new WebDriverException ( "You must enable downloads in order to work with downloadable files." ) ;
482483 }
483484
@@ -494,7 +495,8 @@ public IReadOnlyList<string> GetDownloadableFiles()
494495 public void DownloadFile ( string fileName , string targetDirectory )
495496 {
496497 var enableDownloads = this . Capabilities . GetCapability ( CapabilityType . EnableDownloads ) ;
497- if ( enableDownloads == null || ! ( bool ) enableDownloads ) {
498+ if ( enableDownloads == null || ! ( bool ) enableDownloads )
499+ {
498500 throw new WebDriverException ( "You must enable downloads in order to work with downloadable files." ) ;
499501 }
500502
@@ -508,20 +510,19 @@ public void DownloadFile(string fileName, string targetDirectory)
508510 byte [ ] fileData = Convert . FromBase64String ( contents ) ;
509511
510512 Directory . CreateDirectory ( targetDirectory ) ;
511- string tempFile = Path . Combine ( targetDirectory , "temp.zip" ) ;
512- File . WriteAllBytes ( tempFile , fileData ) ;
513513
514- using ( ZipArchive archive = ZipFile . OpenRead ( tempFile ) )
514+ using ( var memoryReader = new MemoryStream ( fileData ) )
515515 {
516- foreach ( ZipArchiveEntry entry in archive . Entries )
516+ using ( var zipArchive = new ZipArchive ( memoryReader , ZipArchiveMode . Read ) )
517517 {
518- string destinationPath = Path . Combine ( targetDirectory , entry . FullName ) ;
518+ foreach ( ZipArchiveEntry entry in zipArchive . Entries )
519+ {
520+ string destinationPath = Path . Combine ( targetDirectory , entry . FullName ) ;
519521
520- entry . ExtractToFile ( destinationPath ) ;
522+ entry . ExtractToFile ( destinationPath ) ;
523+ }
521524 }
522525 }
523-
524- File . Delete ( tempFile ) ;
525526 }
526527
527528 /// <summary>
@@ -530,7 +531,8 @@ public void DownloadFile(string fileName, string targetDirectory)
530531 public void DeleteDownloadableFiles ( )
531532 {
532533 var enableDownloads = this . Capabilities . GetCapability ( CapabilityType . EnableDownloads ) ;
533- if ( enableDownloads == null || ! ( bool ) enableDownloads ) {
534+ if ( enableDownloads == null || ! ( bool ) enableDownloads )
535+ {
534536 throw new WebDriverException ( "You must enable downloads in order to work with downloadable files." ) ;
535537 }
536538
0 commit comments