Skip to main content

ZipWriter

Encodes a filemap into a Zip Archive. Returns an ArrayBuffer that is a valid Zip Archive and can be written to file.

LoaderCharacteristic
File FormatZIP Archive
Data Format"File Map"
File Extension.zip
File TypeBinary
Encoder TypeAsynchronous
Worker ThreadNo
StreamingNo

Usage​

import {encode, writeFile} from '@loaders.gl/core';
import {ZipWriter} from '@loaders.gl/zip';

const FILE_MAP = {
filename1: arrayBuffer1,
'directory/filename2': arrayBuffer2,
'directory/nested/': ''
};

const arrayBuffer = await encode(FILE_MAP, ZipWriter);
writeFile(zipFileName, arrayBuffer);

File Format​

The file map is an object with keys representing file names or relative paths in the zip file, and values being the contents of each subfile (either ArrayBuffer or String).

  • Nested keys such as folder/file.txt are written as file paths inside the archive.
  • Keys ending with / are written as directory entries.
  • Parent directory entries can also be emitted for nested file keys.

Options​

Archive output always uses type: 'arraybuffer'.

OptionFromTypeDefaultDescription
zip.onUpdate(metadata: {percent: number}) => void() => {}Receives progress updates while the archive is generated.
zip.createFoldersWebsite shields.iobooleanfalseCreates parent directory entries for nested file keys such as folder/sub/file.txt.
jszipobject{}Passes JSZip file and archive generation options through to the underlying writer as an escape hatch.

Explicit slash-suffixed keys are written as directory entries whether or not zip.createFolders is enabled.