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

uzip-module

v1.0.3

Published

Module version of UZIP.js

Downloads

166,186

Readme

uzip-module

zlib inflate, deflate, inflateRaw, deflateRaw, as well as simple in memory zip creation and parsing.

This is a ES6 module version of UZIP.js

It's faster than pako in my tests.

Usage

import {
  deflate,
  deflateRaw,
  inflate,
  inflateRaw,
  encode,
  parse,
} from 'uzip-module';

deflate/inflate

compress Uint8Array using deflate algorithm.

Includes header and footer

const compressed = deflate(uint8Array);

or

const compressed = deflate(uint8Array, {level:9});

decompress Uint8Array that has header and footer with delate algorithm

const uncompressedUint8Array = inflate(compressedUint8Array);

or

const uncompressedUint8Array = inflate(
    compressedUint8Array,
    destinationUint8Array);

deflateRaw, inflateRaw

These take the exact same arguments as inflate and deflate but don't store or expect the header or the footer

encode/parse

encode

Creates a zip file. You pass a JavaScript object of filenames to Uint8Arrays it returns a Uint8Array zip file

const utf8Encoder = new TextEncoder();
const files = {
  'stuff/': utf8Encoder.encode(''),
  'stuff/dog.txt': utf8Encoder.encode('german shepard\n'),
  'stuff/birds/': utf8Encoder.encode(''),
  'stuff/birds/bird.txt': utf8Encoder.encode('parrot\n'),
  'stuff/cat.txt': utf8Encoder.encode('siamese\n'),
  'stuff/long.txt': utf8Encoder.encode(`${new Array(200).fill('compress').join('')}\n`),
}
const zipUint8Array = encode(files);

parse

Does the opposite of encode. Takes a zip Uint8Array and returns a JavaScript object of filenames to Uint8Arrays

Calling parse on the zipUint8Array from the previous example will return the same data seen in files above

const unzippedFiles = parse(files);

You can also call it with an extra true in which case it will just return the filenames and a size and csize for each one. The uncompressed and compressed sizes;

const unzippedFileSizes = parse(files, true);

unzippedFileSizes would have a structure like

{
  "stuff/": {
    "size": 0,
    "csize": 0
  },
  "stuff/dog.txt": {
    "size": 15,
    "csize": 15
  },
  "stuff/long.txt": {
    "size": 1601,
    "csize": 24
  }
}

Notes

All credit goes to the original author Photopea.

I ported this to ES6 modules to use in another library. Originally I thought about putting the various parts in more separate files like the inflate in one file, deflate in another, parse, and encode in others but tree shaking is supposed to handle this stuff more or less so I think just moving it to ES6 modules is enough to get any unused code stripped. The only other think maybe left to do is change the bin and f imports in UZIP.js to import each individual identifier instead of all of them.

Also I spent about an hour trying to get ES6 modules to work with mocha in node but failed so got sick of wasting time and used puppeteer. Patches welcome to remove that dependency.

I didn't make a non-ES6 version. If it's important submit a PR (babel) and I'll take a look.