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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-gzip-nitro

v0.2.0

Published

Fast gzip (inflate/deflate) for React Native via Nitro Modules and zlib (C++/JSI). Drop-in replacement for react-native-gzip.

Readme

react-native-gzip-nitro

npm version license

Fast, native gzip compression and decompression for React Native, built on top of Nitro Modules and zlib.

This library is a drop-in replacement for react-native-gzip that:

  • Uses Nitro Modules instead of the legacy bridge — direct C++/JSI calls, no JSON serialization, no async queue overhead.
  • Runs the actual compression on a background thread so the JS thread stays free.
  • Ships a small, dependency-free native core (zlib + a tiny inline base64 codec — no third-party native deps).
  • Works on both iOS and Android, with the New Architecture (Fabric/TurboModules) enabled.

Why?

react-native-gzip works, but it goes through the old bridge: every call serializes the input/output as a string across the bridge and queues the work on the module method queue. For large payloads (think: API responses, sync uploads, log batches) that's measurable.

react-native-gzip-nitro exposes the same two functions (inflate / deflate) over JSI via Nitro, so:

  • The string crosses the JS/Native boundary as a std::string directly — no JSON.
  • The native work runs on a Nitro background thread pool; you get a real Promise back.
  • The C++ implementation is shared verbatim between iOS and Android (same cpp/HybridGzip.cpp file).

Requirements

  • React Native 0.74+ (New Architecture enabled — required by Nitro).
  • iOS 13.4+.
  • Android minSdk 26+, NDK 27+.
  • react-native-nitro-modules installed in the host app.

Installation

yarn add react-native-gzip-nitro react-native-nitro-modules
# or
npm install react-native-gzip-nitro react-native-nitro-modules

Then install pods:

cd ios && pod install

That's it — autolinking handles the rest on both platforms.

⚠️ New Architecture is required. Make sure newArchEnabled=true in android/gradle.properties and RCT_NEW_ARCH_ENABLED=1 in your iOS environment.

Usage

import { inflate, deflate } from "react-native-gzip-nitro";

// Compress a string -> base64 of gzip bytes
const compressed = await deflate("Hello, world!");
console.log(compressed); // e.g. "H4sIAAAAAAAAA/NIzcnJ1w..."

// Decompress base64-encoded gzip back to the original UTF-8 string
const original = await inflate(compressed);
console.log(original); // "Hello, world!"

API

deflate(data: string): Promise<string>

Gzip-compresses a UTF-8 string and returns a base64-encoded string of the gzip bytes.

  • The output uses standard gzip framing (RFC 1952), with default compression level (Z_DEFAULT_COMPRESSION) and the standard 15+16 window-bit configuration.
  • Runs on a background thread.

inflate(base64: string): Promise<string>

Decompresses a base64-encoded gzip (or zlib) payload and returns the original UTF-8 string.

  • Internally uses inflateInit2(..., 15 + 32), so it auto-detects both gzip (RFC 1952) and zlib (RFC 1950) framing — you can decode either.
  • Whitespace inside the base64 input (newlines, CR, spaces, tabs) is tolerated.
  • Runs on a background thread.

Errors

Both functions reject the returned promise with a JS Error if:

  • the base64 input contains an invalid character (inflate),
  • the gzip stream is truncated or corrupted (inflate),
  • zlib fails to initialize (Z_MEM_ERROR, etc.).
try {
  await inflate("!!!not base64!!!");
} catch (err) {
  // err.message will include the underlying zlib message when available.
}

How it works

                       ┌─────────────────────────────┐
   deflate("...")  ──► │  JS  (your app)             │
                       └────────────┬────────────────┘
                                    │  JSI (Nitro hybrid object)
                       ┌────────────▼────────────────┐
                       │  C++  HybridGzip            │
                       │   ├─ base64Decode/Encode    │
                       │   └─ zlib (deflate/inflate) │
                       └────────────┬────────────────┘
                                    │  background thread
                       ┌────────────▼────────────────┐
                       │  Promise<std::string>       │
                       └─────────────────────────────┘

The TypeScript spec is in src/Gzip.nitro.ts; the C++ implementation lives in cpp/HybridGzip.cpp. Nitrogen-generated bindings live under nitrogen/generated/ and are committed to the repo so consumers don't need to run codegen themselves.

Building from source / contributing

git clone https://github.com/gustavomts/react-native-gzip-nitro.git
cd react-native-gzip-nitro
yarn install
yarn test          # runs the JS-level inflate/deflate tests
yarn specs         # regenerates the Nitrogen bindings if you edit Gzip.nitro.ts

To test inside an app, point your package.json at a local checkout:

{
  "dependencies": {
    "react-native-gzip-nitro": "file:../react-native-gzip-nitro"
  }
}

Project layout

| Path | What's in it | |---|---| | src/ | TypeScript spec (Gzip.nitro.ts) and JS entry point (index.ts) | | cpp/ | Cross-platform C++ implementation (HybridGzip.{hpp,cpp}) | | android/ | Gradle module + CMake setup, links against libz | | ios/ | iOS bits (most logic is in cpp/) | | nitrogen/generated/ | Nitrogen output — regenerate via yarn specs | | __tests__/ | Jest tests for the gzip round-trip on Node's zlib |

Compatibility with react-native-gzip

The exported function names and signatures match react-native-gzip (deflate/inflate, base64 in/out, Promise<string>), so most apps can swap the import:

- import { deflate, inflate } from "react-native-gzip";
+ import { deflate, inflate } from "react-native-gzip-nitro";

The output bytes are byte-compatible: gzip with a standard 32 KB window, default compression level. Anything that decompresses react-native-gzip's output will decompress this library's output, and vice versa.

License

MIT © Gustavo Aires

Acknowledgements

  • Margelo — for the excellent Nitro Modules framework.
  • zlib — the reference compression library this is built on.
  • react-native-gzip — the API this library mirrors.