Programming in HTML5 with JavaScript and CSS3 — Question 53
You develop a webpage that allows a user to download a JPEG image and convert it to a PNG file.
You need to implement the code to download the contents of the JPEG image with no additional decoding.
Which JavaScript function should you use?
Answer options
- A. readAsBinaryString()
- B. readAsArrayBuffer()
- C. readAsDataURL()
- D. readAsText()
Correct answer: B
Explanation
The correct answer is B, readAsArrayBuffer(), because it allows for reading the raw binary data of the JPEG file directly without decoding it. The other options, such as readAsBinaryString() and readAsDataURL(), either decode the data or return it in a different format that is not suitable for direct binary manipulation.