Search Unity

WWW downloaded file size is not same as expected but www.error reports no error?

Discussion in 'Editor & General Support' started by Daylightsburning, Jul 28, 2014.

  1. Daylightsburning

    Daylightsburning

    Joined:
    Oct 24, 2013
    Posts:
    15
    Hi there,
    Today i found WWW downloaded file size is not same as expected, but www.error reports no error? why is this? is there other way can be trusted to download files?

    thank you.
     
  2. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    What kind of difference in file size do you get? Does the downloaded file differ from the expected download? Does the downloaded file not work as you expect?
     
  3. Daylightsburning

    Daylightsburning

    Joined:
    Oct 24, 2013
    Posts:
    15
    Thanks for your reply, Graham Dunnett,

    Downloaded file works fine but still WWW reports a size which is different from the real file size, bigger to be exactly.

    I guess this behavior makes sense : suppose i am the file server and i am about to transfer a file to client, the first thing i will do is to prepare a buffer (8K for example), then divide the file into 8K batches, batch sending the file to the client. but the file size is not always multiples of 8K, so the final batch is not always fully filled, will contain some unused bytes. that's why WWW will report a size that is bigger (than real file size).

    so simply put, WWW.bytesDownloaded is not real file size.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I tried some files and WWW.bytesDownloaded is always 100% accurate. If the number of bytes is higher than you expected I would say it's because it's downloading additional data that you didn't account for (e.g., a web page that has server-side includes, maybe). But it did download that exact number of bytes for a reason, not because the count is incorrect.

    --Eric
     
  5. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    Well, I'd assume some proxy server is messing about with line endings, so perhaps a single newline is replaced with a newline-carriage-return, or it's injecting nulls at the end of the file. Just dump the bytes out to a file and do a diff against what's on the server. As Eric says, Unity reports the size of the file it receives, but isn't responsible for the systems between the server and the client.