If you are looking for a JavaScript code for the compress/decompress algorithm then you have come to the right place.In this post, I will explain you the following points:-
- Compress JSON at client side and decompress using C#
- Compress data in PHP and uncompress in javascript
- Compress XML, String, Variables in Client Sided.
- Compress your JSON data up to 80%
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Get JSON Data From Controller</title>
</head>
<body>
<div>
<input type="button" id="compresss" value="compresss" onclick="GetcompressData();" />
<input type="button" id="uncompress" value="uncompress" onclick="Getuncompressed();" />
</div>
</body>
</html>
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script type="text/javascript">
var LZW = {
compress: function (uncompressed) {
"use strict";
var i,
dictionary = {},
c,
wc,
w = "",
result = [],
dictSize = 256;
for (i = 0; i < 256; i += 1) {
dictionary[String.fromCharCode(i)] = i;
}
for (i = 0; i < uncompressed.length; i += 1) {
c = uncompressed.charAt(i);
wc = w + c;
if (dictionary.hasOwnProperty(wc)) {
w = wc;
} else {
result.push(dictionary[w]);
dictionary[wc] = dictSize++;
w = String(c);
}
}
if (w !== "") {
result.push(dictionary[w]);
}
return result;
},
decompress: function (compressed) {
"use strict";
var i,
dictionary = [],
w,
result,
k,
entry = "",
dictSize = 256;
for (i = 0; i < 256; i += 1) {
dictionary[i] = String.fromCharCode(i);
}
w = String.fromCharCode(compressed[0]);
result = w;
for (i = 1; i < compressed.length; i += 1) {
k = compressed[i];
if (dictionary[k]) {
entry = dictionary[k];
} else {
if (k === dictSize) {
entry = w + w.charAt(0);
} else {
return null;
}
}
result += entry;
dictionary[dictSize++] = w + entry.charAt(0);
w = entry;
}
return result;
}
}
var employees = [
{ "firstName": "John", "lastName": "Doe" },
{ "firstName": "Anna", "lastName": "Smith" },
{ "firstName": "Peter", "lastName": "Jones" }
];
function Getuncompressed() {
var str = JSON.stringify(employees)
var compressdata = LZW.compress(str)
var uncompressdata = LZW.decompress(compressdata)
alert(uncompressdata)
}
function GetcompressData() {
var str = JSON.stringify(employees)
var compressdata = LZW.compress(str)
alert(compressdata)
}
</script>
The post Client-side Data Compression and Decompression with JavaScript appeared first on Software Development | Programming Tutorials.
Read More Articles
- Write a value which contain comma to a CSV file in c#?
- Reading CSV File with cells containing commas c#
- Split CSV with columns may contain ‘,’ Comma C#
- [Simple Way]-Cascading DropDownList in Asp.Net Mvc Using Jquery Ajax
- [Simple Way]-How to get data from database using JQuery Ajax in asp net MVC
- [Simple Way]-ASP.NET Core Upload Multiple File Web API model
- [Simple Way]- Image Upload in .NET Core Web API
- [Easy Way]-Receive File and other form data together in ASP.NET Core Web API
- Replace image in word document using C#
- How to add new rows to an existing word document table in C#
- How to Redirect and post a collection of data to destination URL and redirect to that external URL in MVC c# without using Ajax or client side
- How send event from botframework v3 c# and listen at client side javascript using Direct Line?
- Send javascript object with data and file to asp.net core
- ASP.NET MVC Return File result with additional data to process on client side
- Returning database Id and other data back to ViewModel when creating a WPF Smart Client with WCF
- HTTP Client Request with headers and POST in DotNet?
- Steps to take for figuring out the delay when calling service and loading data with the result?
- problem with sqldatasource and data binding
- How do I deal with a bidirectional dependency between my business and data access layers?
- Read client page data asp.net and c#
- Pause and resume file upload with dotnet core and javascript
- Unit Testing with Specification Pattern and Unit of Work is not returning data on setup
- Unable to connect and get data from remote local Rest API with VPN proxy
- Problem with deleting data from jQuery Datatable and database in ASP.NET Core project
- Client added new sandbox for Dynamics 365, and when trying to insert data I'm getting a 401 error
- How to get all data from API using objects with Newtonsoft.Json and I receive wrong data in xamarin c#
- Generate Random Encryption Key with time tick and store it on client and DB Server Windows Application Form C#
- sort data displayed in table with c# and mongodb
- Call to JavaScript function not working after opening email client with attachment
- C# - Printing a matrix, and updating it with new data
- Reading XML data using XmlDocument with C# - Reading attribute data and splitting the results
- Search and Filter data in ObservableCollection with ICollectionview
- C# LZW Compression and Decompression
- Find the value in gridview using findcontrol and comapre it with data in database
- Data annotations in .Net Core are only client side or they also validate server side?
- How can I send data and make commands with Binding in Xamarin Forms?
- How to open database in Client PC and Connect with it?
- WPF DataGrid with IsAsync data binding don't preserve values when scrolling and sorting
- How to retrieve the data with using the Query from mongoDB and using the properties?
- Issue with data tables about the row and column
- DELETE via linq throwing concurrency exception without concurrency
- SQL Server : executing stored procedure problems
- Object cannot be cast from DBNull to other types in C#
- Syntax error in INSERT INTO statement in c# OleDb Exception cant spot the error
- Add Multiple Options Row Wise To A Table Column
- Need original position number in dictionary
- Unit Testing a Controller method returns null
- JSON data to table using C# .Net MVC
- ComboBox is not updating
- C# - Extracting satellite two line elements from a text file
- Different elements in repeater positioning issue
- Android: how to animate height to wrap_content?
- Fonts don't load in the pdf viewer
- File System Watcher Process called from another class not firing events c#
- Null parameter when trying to pass a blob to C# controller
- Check if the string is number is decimal or integer without using contains comma or dot
- The "Copy" task failed unexpectedly
- StringBuilder Null Checks for MySQL Query
- Filter in DataGrid WPF is not working
- Using named pipes, how to write messages client receives in its form one by one?