diff --git a/files/en-us/web/api/response/bytes/index.md b/files/en-us/web/api/response/bytes/index.md index 5560be5c59490aa..1b53def3164cab1 100644 --- a/files/en-us/web/api/response/bytes/index.md +++ b/files/en-us/web/api/response/bytes/index.md @@ -50,6 +50,125 @@ const string = new TextDecoder().decode(textFile); console.log(string); ``` +### Getting an image file signature + +This example demonstrates how you can use `bytes()` to read the signature bytes of a number of image files, and identify the type. + +#### HTML + +First we define a {{htmlelement("select")}} element for choosing the file type, with corresponding values that indicate the specific file on WikiMedia commons to fetch. + +```html + + + +``` + +```html hidden +

+```
+
+```css hidden
+#log {
+  height: 100px;
+  overflow: scroll;
+  padding: 0.5rem;
+  border: 1px solid black;
+}
+```
+
+#### JavaScript
+
+```js hidden
+const logElement = document.querySelector("#log");
+function log(text) {
+  logElement.innerText = `${logElement.innerText}${text}\n`;
+  logElement.scrollTop = logElement.scrollHeight;
+}
+```
+
+The code first checks if the `bytes()` method is supported.
+If the method is supported it adds an event handler for the [`change` event](/en-US/docs/Web/API/HTMLElement/change_event) event on the `