Skip to main content

Editor.Compression.Zip

Class

Module 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()

static pack(src, destFile): void

Pack files into a zip.

Parameters

ParameterType
srcPath
destFilePath

Returns

void


unpack()

static unpack(src, destDir): void

Unpack the zip file.

Parameters

ParameterType
srcPath
destDirPath

Returns

void