Editor.Compression.Zip
ClassModule to zip and unzip files.
Index
Example
// Editor.Compression.Zip wraps a directory tree into a single .zip and
// (un)packs it back. Below: stage a couple of assets in a temp dir,
// zip the whole directory, then unpack into a sibling location.
const fs = await import('LensStudio:FileSystem');
const tmp = fs.TempDir.create();
const sourceDir = tmp.path.appended(new Editor.Path('assets'));
fs.createDir(sourceDir, { recursive: true } as any);
fs.writeFile(sourceDir.appended(new Editor.Path('readme.txt')), 'sample asset bundle');
fs.writeFile(sourceDir.appended(new Editor.Path('config.json')), JSON.stringify({ version: 1 }));
// Pack the directory into a single archive
const archive = tmp.path.appended(new Editor.Path('assets.zip'));
Editor.Compression.Zip.pack(sourceDir, archive);
console.log('packed:', archive, 'size:', fs.size(archive));
// Unpack into a sibling directory
const out = tmp.path.appended(new Editor.Path('extracted'));
fs.createDir(out, null as any);
Editor.Compression.Zip.unpack(archive, out);
console.log('unpacked entries:', fs.readDir(out, null as any).length);
Methods
pack()
staticpack(src,destFile):void
Pack files into a zip.
Parameters
Returns
void
unpack()
staticunpack(src,destDir):void
Unpack the zip file.
Parameters
Returns
void