B4J Library [B4X] LZStringCompress, the method compress and decompress data through sockets

LZStringCompress, the method compress and decompress data through sockets

LZStringCompress is a String encoding library, helping to speed up communication between the server and applications such as Android and Webapp faster and with a certain level of security.
Instead of string communication which will cause data insecurity, using LZStringCompress will help improve the speed of your applications in case of large text volumes.
LZStringCompress is currently a wrapper for Javascript, B4J, B4A platforms.
Please download the libraries and examples below:

Compress:
Sub Compress() As String
    Dim cpr As LZStringCompress
    cpr.Initialize
    Dim text As String = File.ReadString(File.DirApp & "\www", "testfile.txt")
    Dim cprText As String = cpr.Compress4Socket(text)
    Return cprText
End Sub

Decompress:
<script>
    async function getData() {
  const url = "http://127.0.0.1:51042/compress";
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`Response status: ${response.status}`);
    }
    var gzipsource = await response.text();    
    var puretext = LZString.decompressFromEncodedURIComponent(gzipsource);
    var decompress = document.getElementById('decompress');
    decompress.innerHTML = puretext;
  } catch (error) {
    console.error(error.message);
  }
}
</script>
 

Attachments

  • java_lib.zip
    12.2 KB · Views: 68
  • Example_Server_Client.zip
    8.6 KB · Views: 65
  • b4j_lib.zip
    1.6 KB · Views: 61
  • b4a_lib.zip
    1.6 KB · Views: 67
  • javascript_lib.zip
    1.7 KB · Views: 61
Cookies are required to use this site. You must accept them to continue using the site. Learn more…