-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Declan Chidlow
committed
Oct 16, 2023
1 parent
84e5cba
commit 7386b4b
Showing
3 changed files
with
500 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,52 @@ | ||
# Demo | ||
|
||
Try before you buy - or rather use. These blobby guys are free after all. | ||
|
||
<table> | ||
<tbody id="data"> | ||
<!-- Data will be put in here--> | ||
</tbody> | ||
</table> | ||
|
||
<script src="tarball.js"></script> | ||
<script> | ||
const fetchSampleBlob = () => | ||
fetch("https://cors-anywhere.herokuapp.com/https://github.com/mutant-remix/mutant-remix/releases/download/v54/mtnt_v54_short_svg.tar.gz", { headers: { "X-Requested-With": "https://github.com" } }); | ||
|
||
const fetchStreamToDecompressionStream = (response) => | ||
response.body.pipeThrough(new DecompressionStream("gzip")); | ||
|
||
const decompressionStreamToBlob = (decompressedStream) => new Response(decompressedStream).blob(); | ||
|
||
const blobToDir = (blob) => new tarball.TarReader().readFile(blob); | ||
|
||
const renderDataInList = (data) => { | ||
const tbody = document.getElementById('data'); | ||
|
||
data.forEach(item => { | ||
if (item.type === 'directory') { | ||
// If it's a directory item, create a heading | ||
const heading = document.createElement('h2'); | ||
heading.textContent = item.name; | ||
tbody.appendChild(heading); | ||
} else { | ||
// If it's a file item, create a list item and extract the file name | ||
const listItem = document.createElement('li'); | ||
const fileName = item.name.split('/').pop(); | ||
listItem.textContent = fileName; | ||
tbody.appendChild(listItem); | ||
} | ||
}); | ||
}; | ||
|
||
fetchSampleBlob() | ||
.then(fetchStreamToDecompressionStream) | ||
.then(decompressionStreamToBlob) | ||
.then(blobToDir) | ||
.then(data => { | ||
console.log("Data received:", data); | ||
renderDataInList(data); | ||
}) | ||
.catch(error => console.error(error)); | ||
</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.