
Security News
CISA Rebuffs Funding Concerns as CVE Foundation Draws Criticism
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
A JavaScript library for compressing and decompressing strings using an original algorithm based on the LZ algorithm
lzjs is a JavaScript library that compresses and decompresses strings using an original algorithm based on the LZ algorithm.
This can be particularly useful when storing large amounts of data in storage with size limitations, such as localStorage or cookies.
$ npm install --save lzjs
import
import lzjs from 'lzjs';
require
const lzjs = require('lzjs');
You can install the library via npm or download it from the release list. Use the lzjs.js
or lzjs.min.js
files included in the package.
*Please note that if you use git clone
, even the master branch may be under development.
<script src="lzjs.js"></script>
or the minified lzjs.min.js
:
<script src="lzjs.min.js"></script>
When the script is loaded, the lzjs
object is defined in the global scope (i.e., window.lzjs
).
Compresses data into a binary string.
(string) : Compressed data
Example of compressing and decompressing a string.
const data = 'hello hello hello';
const compressed = lzjs.compress(data);
console.log(compressed); // 'Whello \x80\x82\x84\x86\x83'
const decompressed = lzjs.decompress(compressed);
console.log(decompressed === data); // true
Compress data using onData
and onEnd
events.
const string = 'hello hello hello';
const compressed = [];
lzjs.compress(string, {
onData: (data) => {
compressed.push(data);
},
onEnd: () => {
console.log(compressed.join('')); // 'Whello \x80\x82\x84\x86\x83'
}
});
Decompresses a string that has been compressed with lzjs.compress()
(string) : Decompressed data
Example of decompressing a string that has been compressed with lzjs.compress()
.
const decompressed = lzjs.decompress('Wabc\x80\x82\x81\x83\x83');
console.log(decompressed); // 'abcabcabcabcabc'
Decompress data using onData
and onEnd
events.
const compressed = 'Whello \x80\x82\x84\x86\x83';
const decompressed = [];
lzjs.decompress(compressed, {
onData: (data) => {
decompressed.push(data);
},
onEnd: () => {
console.log(decompressed.join('')); // 'hello hello hello'
}
});
Compresses and encodes data into a Base64 string.
(string) : Compressed and Base64 encoded string
const data = 'hello hello hello';
const compressed = lzjs.compressToBase64(data);
console.log(compressed); // 'V2hlbGxvIMKAwoLChMKGwoM='
Decompresses a string that has been compressed with lzjs.compressToBase64()
.
(string) : Decompressed data
const decompressed = lzjs.decompressFromBase64('V2FiY8KAwoLCgcKDwoM=');
console.log(decompressed); // 'abcabcabcabcabc'
After npm install -g lzjs
lzjs -a something.txt
lzjs -x something.txt.lzjs
-h, --help show Help
-v, --version show Version
-a, --add <file_name> Add file to archive
-x, --extract <file_name> eXtract file
Note that command line compression is only valid for the UTF-8 encoded file.
We welcome contributions from everyone. For bug reports and feature requests, please create an issue on GitHub.
Before submitting a pull request, please run $ npm run test
to ensure there are no errors.
We only accept pull requests that pass all tests.
This project is licensed under the terms of the MIT license. See the LICENSE file for details.
FAQs
A JavaScript library for compressing and decompressing strings using an original algorithm based on the LZ algorithm
The npm package lzjs receives a total of 1,212 weekly downloads. As such, lzjs popularity was classified as popular.
We found that lzjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.