system
Given the following post, respond as if you're commenting on Reddit:
human
Whenever I download a file over HTTP, do the bits come in the correct order? Or are they downloaded in any order and the file assembled on completion.

I am trying to understand the difference between downloading a file to disk vs. using a stream in a programming language like C#.

My understanding of a stream is that it opens a connection and begins transferring bytes of data in small chunks into memory.

**Q1.** When streaming a file like this, do the bytes come in the correct order? I.e. if the bytes were arranged from start to finish on disk, are they streamed in that order?

**Q2.** Then contrast that with downloading a file over HTTP. Does this basically work the same as streaming except it's streamed straight to disk rather than memory?



What's confusing me is how torrents work. Torrents generate a metadata file (the torrent) that divides the target file into chunks which are downloaded in any order. Once complete, the torrent program arranges them altogether.
gpt
data is sent sequentially in packets, each packet is formed of a header and a body section, the header contains different information based on the used protocol, a TCP  packet has a sequence number, so if the packets reached the destination out of order, the computer can rearrange them, while a UDP packet doesn't have a sequence number and data can come in any order.