< Summary

Class:Itinero.IO.Osm.Tiles.Download.DownloadHelper
Assembly:Itinero.IO.Osm.Tiles
File(s):/home/runner/work/routing2/routing2/src/Itinero.IO.Osm.Tiles/Download/DownloadHelper.cs
Covered lines:0
Uncovered lines:19
Coverable lines:19
Total lines:44
Line coverage:0% (0 of 19)
Covered branches:0
Total branches:2
Branch coverage:0% (0 of 2)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
Download(...)0%20%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.IO.Osm.Tiles/Download/DownloadHelper.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using System.IO.Compression;
 4using System.Net;
 5using System.Net.Http;
 6using System.Net.Http.Headers;
 7using System.Web;
 8using Itinero.Logging;
 9
 10namespace Itinero.IO.Osm.Tiles.Download;
 11
 12internal static class DownloadHelper
 13{
 14    /// <summary>
 15    /// Gets a stream for the content at the given url.
 16    /// </summary>
 17    /// <param name="url">The url.</param>
 18    /// <returns>An open stream for the content at the given url.</returns>
 19    public static Stream? Download(string url)
 020    {
 21        try
 022        {
 023            var client = new HttpClient();
 024            client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
 025            var response = client.GetAsync(url);
 026            if (response.Result.StatusCode == HttpStatusCode.NotFound)
 027            {
 028                return null;
 29            }
 30
 031            var stream = response.GetAwaiter().GetResult().Content.ReadAsStreamAsync().GetAwaiter()
 032                .GetResult();
 033            Logger.Log(nameof(DownloadHelper), TraceEventType.Verbose,
 034                $"Downloaded from {url}.");
 035            return new GZipStream(stream, CompressionMode.Decompress);
 36        }
 037        catch (Exception ex)
 038        {
 039            Logger.Log(nameof(DownloadHelper), TraceEventType.Warning,
 040                $"Failed to download from {url}: {ex}.");
 041            return null;
 42        }
 043    }
 44}

Methods/Properties

Download(...)