Skip to content

Commit

Permalink
fixed reporting of file size to download
Browse files Browse the repository at this point in the history
  • Loading branch information
svick committed Jan 29, 2012
1 parent 686afa8 commit a24d5c2
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions Wikipedia SQL dump parser/IO/DownloadStream.cs
Expand Up @@ -14,14 +14,15 @@ public class DownloadStream : Stream
public static bool Verbose { get; set; }

int i = 0;
long position;
private readonly long startPosition;
private long position;
WebResponse response = null;
Stream responseStream = null;

public DownloadStream(string uri, long position = 0)
{
Uri = uri;
this.position = position;
this.startPosition = this.position = position;
Console.Error.Log(string.Format("Downloading {0}.", uri));
}

Expand Down Expand Up @@ -98,21 +99,19 @@ public override int Read(byte[] buffer, int offset, int count)
"{3}: Just downloaded {0:f2} kB, total {1:f2} / {2:f2} MB.",
(float)read / 1024,
(float)position / 1024 / 1024,
(float)response.ContentLength / 1024 / 1024,
(float)(startPosition + response.ContentLength) / 1024 / 1024,
response.ResponseUri.Segments.Last()
));
else if (Log && ++i % 100 == 0)
{
Console.Error.Log(
string.Format(
"{2}: {0:f2} / {1:f2} MB",
(float)position / 1024 / 1024,
(float)response.ContentLength / 1024 / 1024,
response.ResponseUri.Segments.Last()
));
}

return read;
Console.Error.Log(
string.Format(
"{2}: {0:f2} / {1:f2} MB",
(float)position / 1024 / 1024,
(float)(startPosition + response.ContentLength) / 1024 / 1024,
response.ResponseUri.Segments.Last()
));

return read;
}
catch (WebException ex)
{
Expand Down

0 comments on commit a24d5c2

Please sign in to comment.