7.0.3 • Published 5 months ago

capa-zip v7.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

capa-zip

A simple Zip/Unzip plugin for Capacitor v7, supporting iOS and Android platforms.

Overview

This plugin provides zip and unzip functionality for Capacitor applications:

  • iOS Implementation: Uses SSZipArchive library for efficient compression/decompression
  • Android Implementation: Leverages Java's built-in ZipInputStream/ZipOutputStream
  • Platform Support: iOS and Android (Web platform not supported)

Install

npm install capa-zip
npx cap sync

API

Zip file manipulation plugin for Capacitor

Events

The plugin emits progress events during zip/unzip operations:

Zip.addListener('zipProgress', (progress: ZipPluginProgress) => {
  const percentage = (progress.loaded / progress.total) * 100;
  console.log(`Progress: ${percentage.toFixed(2)}%`);
});

Examples

Unzip a file with progress monitoring

// Add progress listener
Zip.addListener('zipProgress', (progress: ZipPluginProgress) => {
  const percentage = (progress.loaded / progress.total) * 100;
  updateProgressUI(percentage);
});

// Perform unzip
try {
  await Zip.unzip({
    sourceFile: 'path/to/archive.zip',
    destinationPath: 'path/to/destination'
  });
  console.log('Unzip completed successfully');
} catch (error) {
  console.error('Unzip failed:', error);
}

Zip a directory

try {
  await Zip.zip({
    sourcePath: 'path/to/directory',
    destinationPath: 'path/to/archive.zip'
  });
  console.log('Zip completed successfully');
} catch (error) {
  console.error('Zip failed:', error);
}

Zip specific files from a directory

try {
  await Zip.zip({
    sourcePath: 'path/to/directory',
    destinationPath: 'path/to/archive.zip',
    files: ['file1.txt', 'subdirectory/file2.jpg']
  });
  console.log('Zip completed successfully');
} catch (error) {
  console.error('Zip failed:', error);
}

addListener('zipProgress', ...)

addListener(eventName: 'zipProgress', listenerFunc: (progress: ZipPluginProgress) => void) => Promise<PluginListenerHandle>

Adds a listener for zip progress events.

ParamTypeDescription
eventName'zipProgress'The name of the event to listen for
listenerFunc(progress: ZipPluginProgress) => voidThe callback function to be called when the event occurs

Returns: Promise<PluginListenerHandle>


unzip(...)

unzip(options: { sourceFile: string; destinationPath: string; }) => Promise<void>

Unzips a file to a specified destination directory.

ParamTypeDescription
options{ sourceFile: string; destinationPath: string; }Options for the unzip operation

Since: 1.0.0


zip(...)

zip(options: { sourcePath: string; destinationPath: string; files?: string[]; }) => Promise<void>

Creates a zip file from a directory or list of files.

ParamTypeDescription
options{ sourcePath: string; destinationPath: string; files?: string[]; }Options for the zip operation

Since: 1.1.0


removeAllListeners()

removeAllListeners() => Promise<void>

Removes all registered event listeners.

Since: 7.0.0


Interfaces

PluginListenerHandle

PropType
remove() => Promise<void>

ZipPluginProgress

Progress event data for zip operations

PropTypeDescription
loadednumberNumber of bytes processed
totalnumberTotal number of bytes to process
7.0.3

5 months ago

7.0.2

5 months ago

7.0.1

5 months ago

7.0.0

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago