Putting it together on the other side
Now the other user should have a collection of chunks that make up the entire file. Since we used the
ordered option in the data channel, the chunks should have come from the other user in order. This means we can put them together in one large data object as we receive them from the other side.
To store our pieces of data, we can push them into a simple array data structure in the client. We will do this directly when the data channel reports that a message has been received. We will also use the opposite decoding function that we covered in the Making chunks readable subsection under the Breaking down a file into chunks section in this chapter, to put our chunks into the right format:
// Add some new global ...