Sys.Zip
Sys.Zip creates and reads ZIP archives in memory and compresses data with gzip in server-side code. Archives are adm-zip objects (npm package adm-zip, version ^0.5.10) limited to the methods that work on memory, so app code cannot read or write server files through them.
Availability: Server
Functions
Section titled “Functions”newZip()
Section titled “newZip()”newZip(): ZipArchiveCreates a new, empty ZIP archive.
Returns: ZipArchive · Availability: Server
const zip = Sys.Zip.newZip()zip.addFile('readme.txt', Buffer.from('Exported by Lowgile', 'utf-8'))zip.addFile('data/orders.json', Buffer.from(JSON.stringify(orders), 'utf-8'))const zipBuffer = zip.toBuffer()readFromBuffer()
Section titled “readFromBuffer()”readFromBuffer(buffer: Buffer | ArrayBuffer): ZipArchiveOpens a ZIP archive from its bytes, for example an uploaded file, to list, read or change its entries.
| Parameter | Type | Description |
|---|---|---|
buffer | Buffer | ArrayBuffer | The ZIP file’s content. A file name is not accepted. |
Returns: ZipArchive · Availability: Server
const zip = Sys.Zip.readFromBuffer(uploadedFile)for (const entry of zip.getEntries()) { if (!entry.isDirectory) Sys.Log.info(entry.entryName, zip.readAsText(entry))}gzip()
Section titled “gzip()”gzip(buffer: Buffer | ArrayBuffer, options?: ZlibOptions): Promise<Buffer<ArrayBufferLike>>Compresses data with gzip, using Node.js zlib.
| Parameter | Type | Description |
|---|---|---|
buffer | Buffer | ArrayBuffer | Data to compress. |
options | ZlibOptions | Node.js zlib options, such as level. |
Returns: Promise<Buffer> · Availability: Server
gunzip()
Section titled “gunzip()”gunzip(buffer: Buffer | ArrayBuffer, options?: ZlibOptions): Promise<Buffer<ArrayBufferLike>>Decompresses gzip data, using Node.js zlib.
| Parameter | Type | Description |
|---|---|---|
buffer | Buffer | ArrayBuffer | gzip-compressed data. |
options | ZlibOptions | Node.js zlib options. |
Returns: Promise<Buffer> · Availability: Server
ZipArchive
Section titled “ZipArchive”type ZipArchive = Omit<AdmZip, ForbiddenMethods>An adm-zip archive without the methods that access the server’s file system. The type cannot be referenced as Sys.Zip.ZipArchive; it is the return type of newZip() and readFromBuffer(). See the adm-zip documentation for the methods’ parameters.
| Methods | Purpose |
|---|---|
getEntries, getEntry, getEntryCount, forEach | List and find entries. |
readFile, readFileAsync, readAsText, readAsTextAsync | Read the content of an entry. |
addFile, updateFile, deleteFile | Add, replace and remove entries. |
addZipComment, getZipComment, addZipEntryComment, getZipEntryComment | Read and write comments. |
test | Check the archive for errors. |
toBuffer, toBufferPromise | Get the archive’s bytes. |
The methods addLocalFile, addLocalFolder, addLocalFolderAsync, addLocalFolderPromise, extractEntryTo, extractAllTo, extractAllToAsync, writeZip and writeZipPromise are blocked: they are not in the type, and at runtime they are undefined. Use Sys.Fs or Sys.Files to store the result of toBuffer().
Availability: Server