Skip to content

Commit

Permalink
Update version 1.5.0
Browse files Browse the repository at this point in the history
   Change the compression library from lz-string to gzip.js to make it simpler to be implemented in server side
    Added the PHP class to inflate the compressed data in PHP server.
    Replace the static example demo with a dynamic demo to be used in a PHP server.
  • Loading branch information
tcorral committed Nov 1, 2013
1 parent 522ae45 commit 36c8897
Show file tree
Hide file tree
Showing 24 changed files with 11,845 additions and 825 deletions.
3 changes: 1 addition & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function (grunt) {
separator: ';'
},
dist: {
src: ['vendor/lz-string-1.0.2.js', 'src/JSONC.js'],
src: ['vendor/crc32.js', 'vendor/rawdeflate.js', 'vendor/rawinflate.js', 'vendor/gzip.js', 'src/JSONC.js'],
dest: 'versions/jsonc.js'
}
},
Expand Down Expand Up @@ -83,5 +83,4 @@ module.exports = function (grunt) {

// Default task(s).
grunt.registerTask('default', ['jshint', 'karma', 'concat', 'uglify', 'compress']);

};
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
JSONC
=====
# Update to version 1.0.0
# Update to version 1.5.0

[![Build Status](https://travis-ci.org/tcorral/JSONC.png)](https://travis-ci.org/tcorral/JSONC)

Expand All @@ -19,8 +19,8 @@ JSONC has two differents approaches to reduce the size of the amount of data to
* Be careful with this method because it's really impressive if you use it with a JSON with a big amount of data, but it
could be awful if you use it to compress JSON objects with small amount of data because it could increase the final size.
* The rate compression could variate from 7.5% to 32.81% depending of the type and values of data.
* *JSONC.pack* - Compress JSON objects using LZW compression algorithm, to make the job JSONC uses the
lz-string library from @pieroxy - https://github.com/pieroxy/lz-string/
* *JSONC.pack* - Compress JSON objects using GZIP compression algorithm, to make the job JSONC uses a modification to
use the gzip library from @beatgammit - https://github.com/beatgammit/gzip-js
* You can use pack to compress any JSON objects even if these objects are not been compressed using JSONC
See Usage for more details.

Expand All @@ -36,25 +36,25 @@ See Usage for more details.
// Returns the original JSON object.
var json = JSONC.decompress( compressedJSON );

####Compress a normal JSON object as a LZW string:
####Compress a normal JSON object as a Gzipped string:

// Returns the LZW representation as string of the JSON object.
var lzwString = JSONC.pack( json );

####Compress a JSON object as a LZW string after compress it using JSONC:
####Compress a JSON object as a Gzipped string after compress it using JSONC:

// Returns the LZW representation as string of the JSON object.
var lzwString = JSONC.pack( json, true );

####Decompress a normal JSON object from a LZW string:
####Decompress a normal JSON object from a Gzipped string:

// Returns the original JSON object.
var json = JSONC.unpack( lzwString );
var json = JSONC.unpack( gzippedString );

####Decompress a JSON compressed object using JSONC from a LZW string:
####Decompress a JSON compressed object using JSONC from a Gzipped string:

// Returns the original JSON object.
var json = JSONC.unpack( lzwString, true );
var json = JSONC.unpack( gzippedString, true );

## Examples of compression

Expand All @@ -65,12 +65,11 @@ See Usage for more details.
Compression rate - 7.5%


Original compressed using lz-string - 3822 bytes
Compressed using JSONC using lz-string - 3689 bytes
Compression rate - 3.4%
Original compressed using gzip.js - 5715 bytes
Compressed using JSONC using gzip.js - 5761 bytes


Compression rate from original to compressed using JSONC and lz-string - 78.71%
Compression rate from original to compressed using JSONC and gzip.js - 66.76%

####Example data2.js.

Expand All @@ -79,9 +78,11 @@ See Usage for more details.
Compression rate - 32.81%


Original compressed using lz-string - 3900 bytes
Compressed using JSONC using lz-string - 3113 bytes
Compression rate - 20.18%
Original compressed using gzip.js - 4279 bytes
Compressed using JSONC using gzip.js - 4664 bytes


Compression rate from original to compressed using JSONC and lz-string - 83.64%
Compression rate from original to compressed using JSONC and gzip.js - 75.49%

##Next steps
####Implement the gzip class in different languages (Java, Ruby...)
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.5.0
Change the compression library from lz-string to gzip.js to make it simpler to be implemented in server side
Added the PHP class to inflate the compressed data in PHP server.
Replace the static example demo with a dynamic demo to be used in a PHP server.
1.0.0
Change the API name of getJSONFromLZWString and getLZWStringFromJSON to pack and unpack that are more readable.
0.3.0
Expand Down
32 changes: 32 additions & 0 deletions demo/GzipJSON.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Class GzipJSON
* Class to decompress gzipped string to JSON.
*/
class GzipJSON {
/**
* Private method that implements the inflate of the data.
* @param $data
* @private
* @return string
*/
private function decode_gzip( $data )
{
return gzinflate( substr( $data, 10, -8 ) );
}

/**
* Method that returns an associated array via json_decode;
* @param $data
* @return mixed
*/
function decompress( $data )
{
$json = json_decode( $this->decode_gzip( utf8_decode( $data ) ), true );
if ( is_null( $json ) )
{
$json = json_decode( $data, true );
}
return $json;
}
}
10 changes: 10 additions & 0 deletions demo/alo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
include_once('GzipJSON.php');

if ( isset( $_POST['json'] ) )
{
$gzjson = new GzipJSON();
$json = $gzjson->decompress($_POST['json']);
$json["test2"] = 3;
echo json_encode($json);
}
38 changes: 38 additions & 0 deletions demo/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#accordion_data div
{
max-height: 200px;
}
.size
{
font-family: monospace;
font-size: 20px;
font-weight: bold;
}
.code
{
font-family: monospace;
font-size: 9px;
}
.fright
{
float: right;
width: 300px;
}
#accordion_usage .ui-accordion-header
{
height: 50px;
}
input[type=button], input[type=submit]
{
font-size: 11px;
}
form div
{
font-size: 12px;
}
ul
{
list-style-type: none;
margin: 0;
padding: 0;
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 36c8897

Please sign in to comment.