npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-zip-stream

v1.0.7

Published

A React Native module for streaming ZIP files.

Downloads

136

Readme

react-native-zip-stream

npm

A React Native module for working with ZIP archives. This module allows you to list the contents of ZIP files, stream files from ZIP archives, create new ZIP files, and unzip files with progress tracking.

Table of Contents

Installation

To install the module, follow these steps:

  1. Add the dependency to your project:

    npm install react-native-zip-stream
  2. For iOS, install the required CocoaPods dependencies:

    cd ios
    pod install

Expo Compatibility

react-native-zip-stream can also be used in Expo projects with some additional configuration. If you're using Expo and want to access the app's local document directory (e.g., to read and write ZIP files), follow these steps:

  1. Install the package:

    expo install react-native-zip-stream
  2. Add the plugin configuration to your app.json:

    {
      "expo": {
        "plugins": ["./node_modules/react-native-zip-stream/plugin"]
      }
    }
  3. Run expo prebuild to generate the necessary native code for your Expo project.

This setup ensures that the app has the correct permissions to access local files and manipulate ZIP files on both Android and iOS.

Usage

List Zip Contents

Lists the contents of a ZIP file. This function returns an array of file names contained within the ZIP archive.

Stream File from Zip

Streams a specific file from a ZIP archive. You can retrieve the file data in one of three formats: base64, arraybuffer, or string.

Unzip File

Extracts all the contents of a ZIP file to a specified destination directory.

Create Zip File

Creates a new ZIP file from the contents of a specified directory.

API Reference

listZipContents

Lists the contents of a ZIP file.

Parameters

  • zipFilePath: string - The full path to the ZIP file.

Returns

  • Promise<string[]> - A promise that resolves to an array of file names inside the ZIP file.

streamFileFromZip

Streams a specific file from the ZIP archive.

Parameters

  • zipFilePath: string - The full path to the ZIP file.
  • entryName: string - The name of the file within the ZIP archive to extract.
  • type: string (optional, default: base64) - The format in which to return the file data. Can be base64, arraybuffer, or string.

Returns

  • Promise<string | ArrayBuffer | Uint8Array> - A promise that resolves to the file content in the specified format.

unzipFile

Extracts all the contents of a ZIP file to a specified destination directory.

Parameters

  • zipFilePath: string - The full path to the ZIP file.
  • destinationPath: string - The path where the contents of the ZIP file should be extracted.

Returns

  • Promise<boolean> - A promise that resolves to true if the operation is successful.

createZipFile

Creates a new ZIP file from the contents of a specified directory.

Parameters

  • destinationPath: string - The full path where the ZIP file should be created.
  • sourcePath: string - The path to the directory or file that should be zipped.

Returns

  • Promise<boolean> - A promise that resolves to true if the ZIP file is created successfully.

Examples

List Zip Contents Example

import { listZipContents } from 'react-native-zip-stream';

const zipFilePath = '/path/to/your/zipfile.zip';

const exampleListZipContents = async () => {
  try {
    const fileNames = await listZipContents(zipFilePath);
    console.log('Files in ZIP:', fileNames);
  } catch (error) {
    console.error('Error listing ZIP contents:', error);
  }
};

Stream File from Zip Example

import { streamFileFromZip } from 'react-native-zip-stream';

const zipFilePath = '/path/to/your/zipfile.zip';
const entryName = 'fileInsideZip.txt';

const exampleStreamFile = async () => {
  try {
    const base64Data = await streamFileFromZip(
      zipFilePath,
      entryName,
      'base64'
    );
    console.log('Base64 Data:', base64Data);

    const arrayBufferData = await streamFileFromZip(
      zipFilePath,
      entryName,
      'arraybuffer'
    );
    console.log('ArrayBuffer Data:', new Uint8Array(arrayBufferData));

    const stringData = await streamFileFromZip(
      zipFilePath,
      entryName,
      'string'
    );
    console.log('String Data:', stringData);
  } catch (error) {
    console.error('Error streaming file:', error);
  }
};

Unzip File Example

import { unzipFile } from 'react-native-zip-stream';

const zipFilePath = '/path/to/your/zipfile.zip';
const destinationPath = '/path/to/extract/';

const exampleUnzipFile = async () => {
  try {
    const success = await unzipFile(zipFilePath, destinationPath);
    console.log('Unzip successful:', success);
  } catch (error) {
    console.error('Error unzipping file:', error);
  }
};

Create Zip File Example

import { createZipFile } from 'react-native-zip-stream';

const sourcePath = '/path/to/source/folder';
const destinationPath = '/path/to/output.zip';

const exampleCreateZipFile = async () => {
  try {
    const success = await createZipFile(destinationPath, sourcePath);
    console.log('Zip creation successful:', success);
  } catch (error) {
    console.error('Error creating zip file:', error);
  }
};