All Projects → SheetJS → Js Adler32

SheetJS / Js Adler32

Licence: apache-2.0
☑️ ADLER-32 checksum

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Js Adler32

Js Crc32
🌀 JS standard CRC-32 implementation
Stars: ✭ 271 (+133.62%)
Mutual labels:  bytes, checksum, data
bytes-java
Bytes is a utility library that makes it easy to create, parse, transform, validate and convert byte arrays in Java. It supports endianness as well as immutability and mutability, so the caller may decide to favor performance.
Stars: ✭ 120 (+3.45%)
Mutual labels:  checksum, bytes
Bits
A bite sized library for dealing with bytes.
Stars: ✭ 16 (-86.21%)
Mutual labels:  bytes, data
Binarykit
💾🔍🧮 BinaryKit helps you to break down binary data into bits and bytes, easily access specific parts and write data to binary.
Stars: ✭ 92 (-20.69%)
Mutual labels:  bytes, data
Datx
DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
Stars: ✭ 111 (-4.31%)
Mutual labels:  data
Awesome Bigdata
A curated list of awesome big data frameworks, ressources and other awesomeness.
Stars: ✭ 10,478 (+8932.76%)
Mutual labels:  data
Server Tech Tree
服务端软件技术树:服务端主流技术九大分类和全景图
Stars: ✭ 106 (-8.62%)
Mutual labels:  data
Data Versioning
Collecting thoughts about data versioning
Stars: ✭ 104 (-10.34%)
Mutual labels:  data
Chartjs Plugin Dragdata
Draggable data points plugin for Chart.js
Stars: ✭ 116 (+0%)
Mutual labels:  data
Just Dashboard
📊 📋 Dashboards using YAML or JSON files
Stars: ✭ 1,511 (+1202.59%)
Mutual labels:  data
Mhworlddata
Generate a SQLite file from MHW data
Stars: ✭ 110 (-5.17%)
Mutual labels:  data
Pyspark Cheatsheet
🐍 Quick reference guide to common patterns & functions in PySpark.
Stars: ✭ 108 (-6.9%)
Mutual labels:  data
Repurrrsive
Recursive lists to use in teaching and examples, because there is no iris data for lists.
Stars: ✭ 112 (-3.45%)
Mutual labels:  data
Vue Table Dynamic
🎉 A dynamic table with sorting, filtering, editing, pagination, multiple select, etc.
Stars: ✭ 106 (-8.62%)
Mutual labels:  data
Amazon S3 Find And Forget
Amazon S3 Find and Forget is a solution to handle data erasure requests from data lakes stored on Amazon S3, for example, pursuant to the European General Data Protection Regulation (GDPR)
Stars: ✭ 115 (-0.86%)
Mutual labels:  data
Platform
Code Climate Engineering Data Platform
Stars: ✭ 104 (-10.34%)
Mutual labels:  data
Hass Data Detective
Explore and analyse your Home Assistant data
Stars: ✭ 109 (-6.03%)
Mutual labels:  data
Patentcrawler
scrapy专利爬虫(停止维护)
Stars: ✭ 114 (-1.72%)
Mutual labels:  data
Caryon
🔖一款基于C++的OI/ACM比赛出题解题辅助工具⭐
Stars: ✭ 109 (-6.03%)
Mutual labels:  data
Babynames
An R package containing US baby names from the SSA
Stars: ✭ 108 (-6.9%)
Mutual labels:  data

adler32

Signed ADLER-32 algorithm implementation in JS (for the browser and nodejs). Emphasis on correctness, performance, and IE6+ support.

Installation

With npm:

$ npm install adler-32

In the browser:

<script src="adler32.js"></script>

The browser exposes a variable ADLER32.

When installed globally, npm installs a script adler32 that computes the checksum for a specified file or standard input.

The script will manipulate module.exports if available . This is not always desirable. To prevent the behavior, define DO_NOT_EXPORT_ADLER.

Usage

In all cases, the relevant function takes an argument representing data and an optional second argument representing the starting "seed" (for running hash).

The return value is a signed 32-bit integer.

  • ADLER32.buf(byte array or buffer[, seed]) assumes the argument is a sequence of 8-bit unsigned integers (nodejs Buffer, Uint8Array or array of bytes).

  • ADLER32.bstr(binary string[, seed]) assumes the argument is a binary string where byte i is the low byte of the UCS-2 char: str.charCodeAt(i) & 0xFF

  • ADLER32.str(string) assumes the argument is a standard JS string and calculates the hash of the UTF-8 encoding.

For example:

// var ADLER32 = require('adler-32');           // uncomment if in node
ADLER32.str("SheetJS")                          // 176947863
ADLER32.bstr("SheetJS")                         // 176947863
ADLER32.buf([ 83, 104, 101, 101, 116, 74, 83 ]) // 176947863

adler32 = ADLER32.buf([83, 104])                // 17825980  "Sh"
adler32 = ADLER32.str("eet", adler32)           // 95486458  "Sheet"
ADLER32.bstr("JS", adler32)                     // 176947863  "SheetJS"

[ADLER32.str("\u2603"),  ADLER32.str("\u0003")]  // [ 73138686, 262148 ]
[ADLER32.bstr("\u2603"), ADLER32.bstr("\u0003")] // [ 262148,   262148 ]
[ADLER32.buf([0x2603]),  ADLER32.buf([0x0003])]  // [ 262148,   262148 ]

Testing

make test will run the nodejs-based test.

To run the in-browser tests, run a local server and go to the ctest directory. make ctestserv will start a python SimpleHTTPServer server on port 8000.

To update the browser artifacts, run make ctest.

To generate the bits file, use the adler32 function from python zlib:

>>> from zlib import adler32
>>> x="foo bar baz٪☃🍣"
>>> adler32(x)
1543572022
>>> adler32(x+x)
-2076896149
>>> adler32(x+x+x)
2023497376

The included adler32.njs script can process files or standard input:

$ echo "this is a test" > t.txt
$ bin/adler32.njs t.txt
726861088

For comparison, the included adler32.py script uses python zlib:

$ bin/adler32.py t.txt
726861088

Performance

make perf will run algorithmic performance tests (which should justify certain decisions in the code).

Bit twiddling is much faster than taking the mod in Safari and Firefox browsers. Instead of taking the literal mod 65521, it is faster to keep it in the integers by bit-shifting: 65536 ~ 15 mod 65521 so for nonnegative integer a:

    a = (a >>> 16) * 65536 + (a & 65535)            [equality]
    a ~ (a >>> 16) * 15    + (a & 65535) mod 65521

The mod is taken at the very end, since the intermediate result may exceed 65521

Magic Number

The magic numbers were chosen so as to not overflow a 31-bit integer:

F[n_] := Reduce[x*(x + 1)*n/2 + (x + 1)*(65521) < (2^31 - 1) && x > 0, x, Integers]
F[255] (* bstr:  x \[Element] Integers && 1 <= x <= 3854 *)
F[127] (* ascii: x \[Element] Integers && 1 <= x <= 5321 *)

Subtract up to 4 elements for the Unicode case.

License

Please consult the attached LICENSE file for details. All rights not explicitly granted by the Apache 2.0 license are reserved by the Original Author.

Badges

Sauce Test Status

Build Status

Coverage Status

Analytics

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].