Skip to content
Mostafa-Samir edited this page Apr 2, 2016 · 11 revisions

API Documentation

Index

ZipLocal

This is the main object in the library and it's the object that you import in the require statment.

ZipLocal.zip(path | buffer | unzippedfs, callback | name, [shiftedCallback])

zips a given file/directory asynchronously.

parameter path | buffer | unzippedfs String | Buffer | ZippedFS : the path to the file/directory to be zipped, the buffer containing the file to be zipped or a ZippedFS form a previously unzipped file.

parameter callback | name Function | String: the function to be called when the zipping is done or the name of the file in case a buffer is passed in the first argument.

parameter shiftedCallback Function: the function to be called when the zipping is done in case a buffer is passed in the first argument.

The callback takes two arguments: a possible error and a ZipExport object.


ZipLocal.unzip(path | buffer, callback)

unzips a given zip file asynchronously

parameter path | buffer String | Buffer : the path to the zip file to be unzipped or the buffer containing it.

parameter callback Function: the function to be called when the unzipping is done. It takes two arguments: a possible error and a ZipExport object.


ZipLocal.sync.zip(path | buffer| unzippedfs, [name])

zips a given file/directory synchronously

parameter path | buffer | unzippedfs String | Buffer | ZippedFS: the path to the file/directory to be zipped, the buffer containing the file to be zipped or a ZippedFS form a previously unzipped file.

parameter name String: the name of the file in case a buffer is passed in the first argument.

returns Object: an instance of ZipExport object.


ZipLocal.sync.unzip(path | buffer)

unzips a given zip file synchronously

parameter path | buffer String | Buffer : the path to the zip file to be unzipped or the buffer containing it.

returns Object: an instance of ZipExport object.

ZipExport

This object handles exporting the zipped/unzipped files. It is passed to callbacks of the asynchronous ZipLocal.zip and ZipLocal.unzip or returned from their synchronous versions.

ZipExport#lowLevel()

returns the underlying `JSZip` object that contains the low level operations that could be done on the zipped/unzipped data.

returns Object: instance of JSZip object.

Review the JSZip API Documentation to know the provided low level operations.


ZipExport#compress()

sets the object so that the exported format will be compressed (only in context of zipping).

returns Object: this instance of ZipExport.


ZipExport#memory()

exports in memory by returning the zipped/unzipped file representation in memory.

returns Object:

  • instance of Buffer in zipping context.
  • instnace of ZippedFS in unzipping context.

ZipExport#save(path, callback)

writes the zipped/unzipped file to disk

parameter path String: the path to the save location. If this parameter was passed no argument or passed null in the context of unzipping, the file will be extracted in the process's current working directory.

parameter callback Function: the function to be called when saving is done (only in asynchronous context). The function is passed a possible error.

ZippedFS

This object provides a mini-filesystem to work with unzipped files in memory. It's returned from `ZipExport#memory` in context of unzipping.

ZippedFS#contents()

returns the list of the files' paths in the unzipped file.

returns Array: an array of the paths of files inside the unzipped file.


ZippedFS#read(path, type)

reads a file in the unzipped file by its path

parameter path String: the path of the file to be read inside the unzipped file.

parameter type String: the return type of the file, either 'text' or 'buffer'.

returns String || Buffer: the contents of the file as either a string or buffer, depending on the passed type.