const tt = require("tar-transform")
const fetch = require('node-fetch')
async function tryExtract() {
const extractStream = tt.extract({
// boolean | "auto". default is "auto".
// indicates whether a gzipped tarball file stream is written to this stream
gzip: true
})
const resp = await fetch("https://codeload.github.com/EqualMa/tar-transform/tar.gz/master")
resp.body.pipe(extractStream)
const entries = []
// `for await ... of ...` is an easy way to consume a stream
// this syntax is available on Node.js >= 10
for await (const entry of extractStream) {
entries.push(entry.headers)
// NOTE: remember to resume the current entry stream to continue
entry.stream.resume()
}
return entries
}
const entryHeaders = await tryExtract()
var html = `<table>
<thead><tr>
<td></td>
<td>path</td>
<td>type</td>
<td>size</td>
</tr></thead>
<tbody>
${entryHeaders.map((h,i)=>`<tr>${[i, h.name, h.type, h.size].map(t=>`<td>${t}</td>`).join("\n")}</tr>`).join("\n")}
</tbody>
</table>`