A basic for library creating and reading USTar files in the browser.
npm install fp-58/btarnpm install fp-58/btar#VERSIONReplace VERSION with the version tag.
import * as btar from "<uri-to-btar>/lib/esmodule.js";const btar = require("btar");define(["btar"], function (btar) {
// Do something here
})define(function (require) {
const btar = require("btar");
})<script src="<uri-to-btar>/lib/index.js"></script>The script declares a global variable named btar.
const archive = await btar.TarArchive.fromBlob(file);const FILE_TYPEFLAG = 0;
// Map of paths to files
let files = new Map();
for (const entry of archive) {
const fullpath = entry.header.prefix + entry.header.name;
if (entry.header.typeflag === FILE_TYPEFLAG) {
files.set(fullpath, entry.content);
}
}const file = new File(["Hello, world!"], "text.txt", {
lastModified: Date.now()
});
archive.addFile("text.txt", file);