ainslec / GWTJSZip

GWT wrapper for jszip.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gwt-jszip

A GWT wrapper for JSZip forked from 99% based upon https://github.com/akjava/GWTJSZip by Aki Miyazaki. It has been tested to work fine with GWT 2.8.2.

It does not use JSInterop.

Why fork it?

The original version dragged in about 10 megabytes of non required libraries and also did not have a Maven build.

This version is over 100 time smaller, is easy to consume using Maven, and also does not place unwanted css inside the compiled GWT application.

GWT Config

In your module’s .gwt.xml file:
<inherits name='com.akjava.gwt.jszip.GWTJSZip'/>

Maven Config

In your maven build file:
   <dependency>
      <groupId>org.ainslec</groupId>
      <artifactId>gwt-jszip</artifactId>
      <version>1.0.0</version>
      <type>gwt-lib</type>
   </dependency>

How to use

Some sample usage of this library can be found here:

Reading files from a base64 representation of a zipfile (snippet code is public domain):
   // TODO :: Need to use other library to open file and convert byte array to base64 representation
   JSZip zipper = JSZip.loadBase64(base64Text);

   JsArrayString files = zipper.getFiles();
   int numFiles        = files.length();

   if (numFiles == 0) {
      log("Zipfile is empty");
   } else {
      for (int i=0; i < numFiles; i++) {
         String fileName          = files.get(i);
         String lowerCaseFileName = fileName.toLowerCase();
         JSFile currentFile       = zipper.getFile(fileName);
         Uint8Array data          = currentFile.asUint8Array();
         byte[] bytes1            = data.toByteArray();
         // Do something with the bytes here !
      }
   }
Saving binary data as a zipfile (snippet code is public domain):
   JSZip z = JSZip.newJSZip();
   z.file("README", "This is the content of a readme file");

   byte[] data = new byte [] {1,2,3,4,5,6,7,8,9,10};
   z.file("mybinaryfile.dat", Uint8Array.createUint8(data), null /*option*/);

   Blob generateBlob = z.generateBlob(null);

   // This is using the GWT FileSaver Wrapper Library (not part of JSZip)
   FileSaver.saveBlob("myzip.zip", generateBlob);

License

This wrapper is Apache Version 2.0 licensed, just as the original https://github.com/akjava/GWTJSZip license was.

JSZip License

jszip is MIT-LICENSED ziptool for javascript. Full details of the JSZip license are included in the "jszip_LICENSE.markdown" file.

What does the fork change?

The fork drags in the 'Blob' class from https://github.com/akjava/akjava_gwtlib , which is also Apache Version 2.0 licensed from the same author.

This means that there are no dependencies, so that this library can be used easily without pulling huge libraries like guava.

Why is the group id 'org.ainslec' instead of 'com.akjava'?

Maven Central rules specify that forks need to use the group id of the person who forked the library. This is not the mainline build of GWTJSZip.

About

GWT wrapper for jszip.js

License:Apache License 2.0


Languages

Language:Java 100.0%