From 6ec962230e974d743a10ad0d368d7500d8221929 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Thu, 23 Feb 2006 00:14:00 +0000 Subject: [PATCH] 2006-02-22 James Willcox * src/Database.cs (DownloadSong): don't assume that the length argument is valid. svn path=/trunk/daap-sharp/; revision=57188 --- ChangeLog | 5 +++++ src/Database.cs | 13 ++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa99be8..c4b295a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-02-22 James Willcox + + * src/Database.cs (DownloadSong): don't assume that the length + argument is valid. + 2006-02-21 James Willcox * configure.ac: bump to 0.3.1 diff --git a/src/Database.cs b/src/Database.cs index ecfca46..1e5ecf6 100644 --- a/src/Database.cs +++ b/src/Database.cs @@ -376,13 +376,12 @@ namespace DAAP { try { using (BinaryReader reader = new BinaryReader (response.GetResponseStream ())) { int count = 0; - - while (count < response.ContentLength) { - byte[] buf = reader.ReadBytes ((int) Math.Min (ChunkLength, - response.ContentLength - ChunkLength)); - writer.Write (buf); - count += buf.Length; - } + byte[] buf = new byte[ChunkLength]; + + do { + count = reader.Read (buf, 0, ChunkLength); + writer.Write (buf, 0, count); + } while (count == ChunkLength); } } finally { writer.Close ();