Fixed stream writing to account for lack of Stream.CopyTo.