• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

☑️ ADLER-32 checksum

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 adler32-cli package includes scripts for processing files or text on standard input:

$ echo "this is a test" > t.txt
$ adler32-cli t.txt
726861088

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

$ packages/adler32-cli/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

More Repositories

1

sheetjs

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs
JavaScript
33,614
star
2

js-word

✒️ Word Processing Document Library
Rich Text Format
1,302
star
3

j

❌ Multi-format spreadsheet CLI (now merged in http://github.com/sheetjs/js-xlsx )
JavaScript
345
star
4

js-crc32

🌀 JS standard CRC-32 and CRC32C implementation
Python
330
star
5

SheetJS.github.io

:goberserk: SheetJS Spreadsheet Parser/Writer tests and demos
HTML
262
star
6

printj

📜 sprintf for JS
JavaScript
196
star
7

test_files

📚 SheetJS Test Files (XLS/XLSX/XLSB and other spreadsheet formats)
HTML
162
star
8

ssf

📝 Spreadsheet Number Formatter
JavaScript
157
star
9

js-codepage

💱 Codepages for JS
JavaScript
147
star
10

js-ppt

Pure JS PowerPoint 97-2003 (PPT) Parser
JavaScript
107
star
11

k

❌ Spreadsheet Differ
JavaScript
85
star
12

frac

➗ rational approximation with bounded denominator
JavaScript
72
star
13

sgds

Simple REST Server that emulates Google Docs interface using your Excel files (currently read-only)
JavaScript
71
star
14

js-cfb

💾 OLE File Container Format
JavaScript
59
star
15

js-harb

❌ Host of Archaic Representations of Books (now merged in http://github.com/sheetjs/js-xlsx )
JavaScript
55
star
16

jxls

Snapshot for test files. https://github.com/jxlsteam/jxls is the current repo for the project
Java
51
star
17

sheetaki

🔣 Spreadsheet CSV conversion microservice
HTML
50
star
18

pb

📋 Access HTML and other pasteboards from JS and command line
JavaScript
35
star
19

bessel

Bessel Functions in JS
JavaScript
31
star
20

sheets

generate pretty ascii tables from XLS/XLSX/XLSB/XLSM/XML workbooks
JavaScript
23
star
21

wk

🔍 Preview spreadsheets in your terminal!
TypeScript
20
star
22

enron_xls

Spreadsheets from the Enron Corpus
JavaScript
20
star
23

voc

👷 A Literate Programming Framework for JS and compile-to-JS languages.
JavaScript
20
star
24

maths

Collection of Math Functions for NodeJS
JavaScript
18
star
25

py-xls

PyPI xls module
Python
16
star
26

sheet.js.org

sheet.js.org
15
star
27

js-wmf

Windows MetaFile (wmf) processor
TypeScript
14
star
28

bz2

bzip2 for JavaScript
JavaScript
13
star
29

js-vdc

🎧 van der Corput low-discrepancy sequences
HTML
13
star
30

cfb-editor

💼 ZIP/CFB/MIME Archive Editor
JavaScript
9
star
31

node-exit-on-epipe

💥 Cleanly exit on pipe errors
JavaScript
9
star
32

xlsx-nw-demo

node-webkit XLSX demo
JavaScript
7
star
33

rooster

🐓 File filter for version control systems.
Go
7
star
34

docs.sheetjs.com

SheetJS Community Edition Docs repo
HTML
6
star
35

notes

Various file format notes
TypeScript
5
star
36

js-funzip

`funzip` for nodejs
TypeScript
4
star
37

libreoffice_test-files

Mirror of LO Test Files (see https://bugs.freedesktop.org/show_bug.cgi?id=85756)
Python
3
star
38

flat-sheet

demo for https://docs.sheetjs.com/docs/demos/hosting/github
TypeScript
2
star
39

sheetjs-npm-placeholder

Placeholder for the `sheetjs` package on npm
1
star
40

test_files_pres

Presentation Test Files
1
star