Giter VIP home page Giter VIP logo

jsziptools's Introduction

jsziptools

It's a utility of zlib, gzip and zip format binary data.

API Reference

suported browser

chrome, firefox, IE10.

examples

zlib

decompress compressed swf file:

    jz.utils.load('compressed.swf', function(swf){
      var header = new Uint8Array(swf, 0, 8);
      var decompressedData = jz.zlib.decompress(new Uint8Array(swf, 8));
    });

gzip

compress and download:

    var text = 'aaaaaabbbbbbbbbbbccccccccc';
    var gzbuff = jz.gz.compress(jz.utils.stringToArrayBuffer(text));
    var URL = window.URL || window.webkitURL;
    var bb = new jz.BlobBuilder();
    bb.append(gzbuff);
    location.href = URL.createObjectURL(bb.getBlob());

zip

zip:

    var files = [
      {name: "foo", dir: [ //folder
        {name: "hello.txt", buffer: "Hello World!"}, //string
        {name: "bar.js", buffer: buffer}, //ArrayBuffer
        {name: "hoge.mp3", url: "audiodata/hoge.mp3"} //xhr
      ]}
    ];
    
    //async(recommend!)
    jz.zip.pack({
      files: files,
      level: 5, //compress level
      complete: function(buffer){
        //...
      }
    });

    //sync(not support xhr.)
    var buffer = jz.zip.pack({
      files: [{name: "a.txt", "aaa"}],
      level: 4
    });
    
    //set compress level each files.
    var files = [
      {name: "mimetype", buffer: "application/epub+zip", level: 0}, //string
      {name: "META-INF", dir: [ //folder
        {name: "container.xml", buffer: buffer, level: 0}, //ArrayBuffer
      ]},
      {name: "package.opf", url: "package.opf", level: 6},
      {name: "foo.xhtml", url: "foo.xhtml", level: 9} //xhr
    ];
    
    jz.zip.pack({
      files: files,
      complete: function(buffer){
        //...
      }
    });

unzip:

    var loader = jz.zip.unpack(buffer);
    //get file pathes.
    loader.getFileNames();
    //file is read lazy.
    loader.getFileAsText(loader.getFileNames[0], function(result){
      alert(result);
    });

custom build

You can use build.py to build jsziptools.

$ #see help
$ ./build.py -h
usage: build.py [-h] [-C COMPILER_PATH] [-m MODULES] [-o OUTPUT_PATH]
                [-c CONF_FILE_PATH]

optional arguments:
  -h, --help         show this help message and exit
  -C COMPILER_PATH   Set a Closure Compiler path.
  -m MODULES         Set module names you want to use.
  -o OUTPUT_PATH     Set a output file path.
  -c CONF_FILE_PATH  Set a configuration file path.
$ #select modules
$ ./build.py -m gz.decompress zlib.decompress -o build/gz_zlib_decomp.min.js

module list:

  • gz.compress
  • gz.decompress
  • gz (gz.compressandgz.decompess)
  • zlib.compress
  • zlib.decompress
  • zlib (zlib.compressandzlib.decompress)
  • zip.pack
  • zip.unpack
  • zip (zip.packandzip.unpack)

You also can write a configuration file that is written in json.

Example of a configuration file:

{
    "compiler": "./compiler.jar",
    "output": "./build/jsziptools.unzip.min.js",
    "files": [
        "lib/DataViewUtils/build/dataview.utils.min.js",
        "src/jsziptools.js",
        "src/utils.js",
        "src/algorithms/crc32.js",
        "src/algorithms/inflate.js",
        "src/zip.unpack.js"
    ]
}

Usage:

$ ./build.py -c buildconf.json

jsziptools's People

Contributors

brentbrownfield avatar ukyo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.