Skip to content

Commit

Permalink
Replace XMLHR with Fetch in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
egoroof committed Dec 16, 2023
1 parent fb6b255 commit 6f0be52
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,24 @@ For example you can create file input and use
</script>
```

##### XMLHttpRequest
##### Fetch

To get arrayBuffer from remote server you can use
[XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest):
To get arrayBuffer from a remote server you can use
[Fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API):

```js
const xhr = new XMLHttpRequest();
xhr.open('GET', urlToSongFile, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (xhr.status === 200) {
const arrayBuffer = xhr.response;
// go next
} else {
// handle error
console.error(xhr.statusText + ' (' + xhr.status + ')');
}
};
xhr.onerror = function () {
const request = await fetch(urlToSongFile);
if (!request.ok) {
// handle error
console.error('Network error');
};
xhr.send();
console.error(`Unable to fetch ${urlToSongFile}`);
}
const arrayBuffer = await request.arrayBuffer();
// go next
```

#### Add a tag

Create new `ID3Writer` instance with arrayBuffer of your song, set frames and add a tag:
Create a new `ID3Writer` instance with arrayBuffer of your song, set frames and add a tag:

```js
// arrayBuffer of song or empty arrayBuffer if you just want only id3 tag without song
Expand Down Expand Up @@ -162,7 +152,7 @@ saveAs(blob, 'song with tags.mp3');
```

If you are writing chromium extension you can save file using
[Downloads API](https://developer.chrome.com/extensions/downloads):
[Downloads API](https://developer.chrome.com/docs/extensions/reference/api/downloads):

```js
chrome.downloads.download({
Expand Down

0 comments on commit 6f0be52

Please sign in to comment.