Skip to content

Instantly share code, notes, and snippets.

@Meshiest
Created September 17, 2020 19:52
Show Gist options
  • Save Meshiest/6e7dea32b13a12c9e7dd917b60f073de to your computer and use it in GitHub Desktop.
Save Meshiest/6e7dea32b13a12c9e7dd917b60f073de to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<script src="https://cdn.jsdelivr.net/npm/brs-js/dist/dist.js"></script>
<!-- Files uploaded will be -->
<input id="fileInput" type="file">
<a id="anchor" download="cloned.brs">Download</a>
<!-- This will be filled with the save object as JSON or the error message -->
<pre id="jsonElem"></pre>
<script>
fileInput.addEventListener('change', e => {
const file = e.target.files[0];
if (file) {
// Read the file into a byte array
file.arrayBuffer()
.then(buff => {
const save = BRS.read(buff);
// Log the save object
console.log(save);
// Render the save object as formatted JSON
jsonElem.innerText = '';
const blob = new Blob([new Uint8Array(BRS.write(save))]);
anchor.href = URL.createObjectURL(blob);
})
.catch(err => {
// Display the error
jsonElem.innerText = 'Error: ' + err.message;
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment