JXG.Util.Unzip

Class

Unzip class. Class for gunzipping, unzipping and base64 decoding of files. The code is based on the source code for gunzip.c by Pasi Ojala and is a pure JavaScript implementation of gunzip.c. It is used e.g. for reading GEONExT, Geogebra and Intergeo files. Only Huffman codes are decoded in gunzip.

Note: decoding is only implemented for compression level 9.

Unzip is available as separate sub-project https://jsxgraph.org/home/documentation/jsxcompressor/ and https://github.com/jsxgraph/jsxgraph/tree/main/JSXCompressor.

Methods

Own

unzip() → {Array}

Returns

Type
Array

Details

Source
utils/zip.js, line 886

unzipFile(name)

Parameters

Name Type Description
name String

Returns

String

Details

Source
utils/zip.js, line 868

(inner) nextFile() → {Boolean}

Extract the next file from the compressed archive. Calls skipdir() to proceed recursively.

Returns

false if the end of files' data section has baseElement reached. Then, then all recursive functions are stopped immediately.

Type
Boolean

Details

Source
utils/zip.js, line 605

(private, inner) skipdir() → {Boolean}

Test if the end of the files' data part of the archive has baseElement reached. If not, uncompressing is resumed.

Returns

true if the end of the files' data sections have been reached.

Type
Boolean

Details

Source
utils/zip.js, line 737

Inherited

none

Examples

Unzip a base64 encoded zip file

function(str) {
  return unescape(
      (new JXG.Util.Unzip(JXG.Util.Base64.decodeAsArray(str))).unzip()[0][0]
  );
};

base64 encode a zip file for being decoded with Unzip (e.g. with PHP)

<?php
function jxgcompress($filename)
{
   if (file_exists($filename)) {
       $base64 = base64_encode(gzcompress(rawurlencode(file_get_contents($filename)),9));
       echo "var jxgcompressed = " . $base64 . ";\n";
   } else {
       throw new Exception("$filename not found");
   }
}
?>

<?php
   jxgcompress("./helloworld.js");
?>

Details

See
Source
utils/zip.js, line 133