ZipWriter
Encodes a filemap into a Zip Archive. Returns an ArrayBuffer that is a valid Zip Archive and can be written to file.
| Loader | Characteristic |
|---|---|
| File Format | ZIP Archive |
| Data Format | "File Map" |
| File Extension | .zip |
| File Type | Binary |
| Encoder Type | Asynchronous |
| Worker Thread | No |
| Streaming | No |
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.txtare 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'.
Explicit slash-suffixed keys are written as directory entries whether or not zip.createFolders is enabled.