# zip-file-server

> ZipFileServer is a lightweight library that serves as an intermediary between the web client and the server

Latest version **0.4.2** (published 2026-05-15) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install zip-file-server
pnpm add zip-file-server
yarn add zip-file-server
bun add zip-file-server
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.2 |
| Published | 2026-05-15 |
| First published | 2023-11-16 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 291.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Happy Wang |
| Maintainers | happywang |

## Links

- npm: https://www.npmjs.com/package/zip-file-server
- Repository: https://github.com/shuizhongyueming/zip-file-server
- Issues: https://github.com/shuizhongyueming/zip-file-server/issues
- npm.io page: https://npm.io/package/zip-file-server

## Dependencies (1)

- [@zip.js/zip.js](https://npm.io/package/@zip.js/zip.js.md) ^2.7.45

## Recent versions

- 0.4.2 (latest) — 2026-05-15
- 0.4.1 — 2024-08-29
- 0.4.0 — 2024-08-28
- 0.3.4 — 2024-08-09
- 0.3.3 — 2024-07-26
- 0.3.2 — 2024-06-17
- 0.3.1 — 2024-06-14
- 0.3.0 — 2024-06-13
- 0.2.10 — 2024-04-26
- 0.2.9 — 2024-04-25
- 0.2.8 — 2023-12-14
- 0.2.7 — 2023-12-13
- 0.2.6 — 2023-11-28
- 0.2.5 — 2023-11-21
- 0.2.4 — 2023-11-20
- … 5 more at https://npm.io/package/zip-file-server/versions

## README

ZipFileServer is a lightweight library that serves as an intermediary between the web client and the server. 

It provides an efficient way to package and download numerous fragmented files as required.

The Core zip inflate feature is based on [zip.js](https://github.com/gildas-lormeau/zip.js).

## Table of Contents

- [Overview](#overview)
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

## Overview

When ZipFileServer receives a file request, it prioritizes searching and delivering from the corresponding remote zip package.

This process is seamless for both the client and the server.

## Installation

To install ZipFileServer, run the following command:

```bash
npm install zip-file-server
```

## Usage

Please refer to the provided example for detailed usage.

```javascript
  import {ZipFileServer} from '../dist/main.js';

  const server = new ZipFileServer({
    remotes: [
      {
        name: 'bundle',
        prefix: 'bundle/',
        zipUrl: 'bundle.zip'
      },
      {
        name: 'res',
        prefix: 'res/',
        zipUrl: 'res.zip'
      }
    ],
    fallbackUrl: '/example/',
    fetch: (opt) => fetch(opt)
  });

  window.server = server;

  function showImg(url) {
    return new Promise(resolve => {
      const img = new Image();
      server.getUrl(url).then(({url, onComplete}) => {
        img.src = url;
        img.onload = () => {
          onComplete();
          resolve();
        };
      });
      document.body.appendChild(img);
    })
  }

  server.preload('res').then(() => {
    console.log('preload res.zip done');

    // no need to load res.zip again
    showImg('res/img.png').then(() => {
      console.log('load res/img.png done');

      // unload res.zip
      server.unload('res');

      // this time will load res.zip again
      showImg('res/img2.png').then(() => {
        console.log('load res/img2.png done');
      });
    });
  });

  server.getData('bundle/data.json')
    .then(data => data.json())
    .then(data => console.log('data.json', data));

  showImg('bundle/img.png');

  server.getData('bundle/info.txt').then(res => res.text()).then(data => {
    console.log('info.txt', data);
  });
```

## License

ZipFileServer is BSD-3-Clause licensed

---
_Source: https://npm.io/package/zip-file-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
