Skip to content

webciter/jsbcl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

JSBCL v1.0.0 documentation

JavaScript Bootstrapped Compression Library

Table Of Contents

About JSBCL

JSBCL short for JavaScript Bootstrapped Compression Library, JSBCL is a collection of scripts designed to allow developers easy implementation of compressed archives directly in the browser.JSBCL currently uses LZMA (Lempel–Ziv–Markov chain Algorithm) format as it's base compression format, developers can implement this advanced compression format, with a few lines of code.

Setting Up

Adding Your Own Scripts

You can add your own scripts in the release and debug directories, files stored in the js/release directory MUST be compressed with LZMA format and MUST only contain one file and end in the .js.lzma extension all lowercase.Thus files stored in the js/debug directory are uncompressed and generally not minified, to aid autocompletion of your ide.

file: public_html/js/init.js

               this.requires = {
                    /* debug/release - these two objects must match */
                    debug:      new Array(
                        "js/debug/app.js"
                    ), 

                    release:    new Array(
                        "js/release/app.js.lzma",
                    ),

                },

 

Release/Debug

Switching from debug to release when you have completed your project your LZMA compressed scripts should be stored in the release directory this is where the magic takes place. change this.debug to true or false depending if you are using compressed or decompressed files

file: public_html/js/init.js

            this.debug = true,  /* which files to load */
        

Make sure you add at least one object from each file to the if condition below, this will make sure all files have been added before the application continues. Use the || operator. NOTE: if you don't do this correctly your application will break

file: public_html/js/init.js

          /* check if loaded */
          this.initTimer = setInterval(function(){
                  /* Make sure all new scripts are added to the loader */
                  if(
                          typeof window.app === 'undefined'
                          ){

                  }else{
                      start(this.initTimer);
                  }
              }
          , 300);

Getting Data

This section dives into the details of the framework

Making a request For JSON

To make a request for a compressed JSON file store it in the arc directory, this is NOT required, JSON files MUST have the .json.lzma file extension for this to work. You can make a request using the following code assuming the file is stored in the appropriate directory or served by some dynamic means.

            window.loadJSBinary("/arc/jsonTest.json.lzma",'testJson');

To get JSON you MUST pass the URL followed by the NAME string which you will need later to retrieve the data as an object. The data retrieved from this line for code will be inserted into the window.json object you can access this object by typing window.json.testJson.

This JSON data will not be avaliable instantly, you must wait untill it has been loaded using the following function.

            window.jsonDone(['testJson'], window.calledWhenDone);

This function accepts a Array of JSON NAME to test if available as defined previously, The second argument is a function callback which will be executed once complete for example.

                window.calledWhenDone = function(){
                    console.log(window.json.testJson);
                }

window.json.testJson would be the JSON Object you named above, all JSON Objects you get through loadJSBinary will be added to window.json

Making a request for TEXT/HTML Files.

To make a request for a TEXT file use the following code

                window.loadText("arc/documentation.html.lzma",".doc", window.const.method.APPEND);

This function accepts several parameters the first parameter is the path of the archive, a single compressed file in plain text format using .lzma extension, The second parameter is the selector used to insert the data into and the final parameter is the METHOD of insertion witch currently supports "APPEND", "PREPEND" or you can use the strings stored in window.const.method witch is optional default to "APPEND".

Releases

No releases published

Packages

No packages published