class Zip
The Zip class allows to access content of zip files and blobs.
Zip Archive can be mounted at particular URL:
const rs = await fetch("remote url");
const archive = Zip.openData(rs.arrayBuffer());
archive.mountTo("this://mounts/test/");
After that data from the archive can be accessed as any other resource:
<img src="this://mounts/test/images/foo.png">
import {Bar} from "this://mounts/test/bar.js";
and so on.
Static methods
openFile()
Zip.openFile(path:string [,password]): Zip
Opens zip file for reading. Returns instance of Zip class.
openData()
Zip.openData(data:ArrayBuffer[,password]): Zip
Opens zip blob for reading. Returns instance of Zip class.
toData()
Zip.toData(provider[,password]): ArrayBuffer
Creates zipped blob from items supplied by provider function. provider has the following signature:
function(n) : [localPath:string, itemData: ArrayBuffer [,fileAttributes:int] | null
toFile()
Zip.toFile(path:string, provider[,password]): true|false
Creates zip file from items supplied by provider function. provider has the following signature:
function(n) : [localPath:string, itemData: ArrayBuffer [,fileAttributes:int] | null
Properties:
length
zip.length - reports total number of items in the zip;
Methods:
zip.item()
zip.item(index:int | path:string) ZipItem
Fetches zip item either:
- by index that must be in range [0 .. zip.length).
- or by its path (local to the zip).
(iterator)
The Zip supports iterator to walk over content of the zip:
const zip = Zip.openFile(...);
for(const item of zip)
console.log(item.path);
class ZipItem
ZipItem is a structure that represents single entry inside the zip.
Properties:
item.isDir:bool- true if the item represents directory inside the zip;item.isFile:bool- true if the item represents file;item.path:string- local path of the item inside the zip;item.data:ArrayBuffer- data of the item as ArrayBuffer. Usesrt.decode(arrayBuffer,"utf-8")to convert the data to string if needed.item.attributes:int- zip::external_fa - file attributes, see the answer on this question.