Introducing the HTML5 File API
Data channels help us to transmit data (files) between peers. Nevertheless, it doesn't provide any mechanism to read and write files. So, we need some mechanism to be able to read/write files.
For the purpose of filesystem access, we will use the HTML5 File API. It provides a standard way to interact with local files. Using this API, you can create and read files, create thumbnails for image files, save application preferences, and more. You can also verify on the client side; if a customer wants to upload the MIME type of file, you can restrict the uploading by the file size.
When reading files, we will use the
FileReader
object. It reads files asynchronously and provides the following four ways (methods) to read them:
readAsBinaryString
: This will read a file into a binary string. Every byte is represented by an integer in the range from 0 to 255.readAsText
: This reads the file as a text string. By default, the result string is decoded as UTF-8. You can use...