0.2.10 • Published 16 days ago

zip-file-server v0.2.10

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
16 days ago

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.

Table of Contents

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:

npm install zip-file-server

Usage

Please refer to the provided example for detailed usage.

  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

0.2.10

16 days ago

0.2.9

16 days ago

0.2.8

5 months ago

0.2.7

5 months ago

0.2.6

6 months ago

0.2.5

6 months ago

0.2.4

6 months ago

0.2.3

6 months ago

0.2.2

6 months ago

0.2.1

6 months ago

0.2.0

6 months ago

0.1.0

6 months ago