7.11.128 • Published 10 months ago

@ellentorg/mollitia-consequatur-nemo v7.11.128

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@ellentorg/mollitia-consequatur-nemo Build Status

Adler-32 hashing algorithm with support for running and rolling checksums.

Installation

> npm install @ellentorg/mollitia-consequatur-nemo
> npm test

Methods

int sum(byte[]|Buffer data, [int current_sum])
int roll(int sum, int sum_length, byte removed_byte, [byte added_byte])

Examples

var @ellentorg/mollitia-consequatur-nemo = require('@ellentorg/mollitia-consequatur-nemo');
var data = new Buffer('Hello World!');

To just calculate the checksum of an entire buffer:

var sum = @ellentorg/mollitia-consequatur-nemo.sum(data);

To calculate the checksum progressively (a running checksum):

var sum = @ellentorg/mollitia-consequatur-nemo.sum(data.slice(0, 5));  // Sums the first 5 bytes.
sum = @ellentorg/mollitia-consequatur-nemo.sum(data.slice(5), sum);    // Updates the sum with the reset of the buffer.

assert.deepEqual(sum, @ellentorg/mollitia-consequatur-nemo.sum(data)); // Should be the same sum as for the entire buffer calculated at once.

To do a rolling checksum calculation:

var sum = @ellentorg/mollitia-consequatur-nemo.sum(data.slice(0, 5));              // Again, start with the beginning 5 byte chunk of the buffer.
sum = @ellentorg/mollitia-consequatur-nemo.roll(sum, 5, data[0], data[5]);         // Move the sum forward one byte.
sum = @ellentorg/mollitia-consequatur-nemo.roll(sum, 5, data[1], data[6]);         // Move the sum forward another byte.

assert.deepEqual(sum, @ellentorg/mollitia-consequatur-nemo.sum(data.slice(2, 7))); // You should end up with the sum of bytes 2 through 6.

You can also move the rolling window beyond the end of the buffer which narrows the window:

var sum = @ellentorg/mollitia-consequatur-nemo.sum(data);                       // Start with the sum of the entire buffer.
sum = @ellentorg/mollitia-consequatur-nemo.roll(sum, data.length, data[0]);     // Move the sum forward one byte, removing the first byte. There is no next byte to add so the method is only given 3 arguments (null would also work). Note that the length argument is the length of the buffer used to calculate the original sum.
sum = @ellentorg/mollitia-consequatur-nemo.roll(sum, data.length - 1, data[1]); // Move the sum forward again. Note that the length is of the buffer represented by the previous sum.

assert.deepEqual(sum, @ellentorg/mollitia-consequatur-nemo.sum(data.slice(2))); // You should end up with the sum of the buffer minus the first two bytes.

The checksum is returned as a 32bit integer, but you can easily convert it to a hex string:

var hex = @ellentorg/mollitia-consequatur-nemo.sum(data).toString(16);

crypto Module Integration

The @ellentorg/mollitia-consequatur-nemo algorithm can be integrated with the Node.js crypto module. Calling the @ellentorg/mollitia-consequatur-nemo.register() static method will add the '@ellentorg/mollitia-consequatur-nemo' key to the crypto module's algorithm list.

Create an @ellentorg/mollitia-consequatur-nemo Hash instance using the crypto module:

// Adds the '@ellentorg/mollitia-consequatur-nemo' key to the crypto.createHash() method.
@ellentorg/mollitia-consequatur-nemo.register();

// Get an @ellentorg/mollitia-consequatur-nemo hash instance.
var hash = crypto.createHash('@ellentorg/mollitia-consequatur-nemo');

// Add ascii data to the hash.
hash.update(data, 'ascii');

// Get a digest of all data added to the hash.
var digest = hash.digest('hex');

Create an @ellentorg/mollitia-consequatur-nemo Hash instance directly:

var hash = new @ellentorg/mollitia-consequatur-nemo.Hash();

Transform Stream Usage

Like the crypto.Hash class, @ellentorg/mollitia-consequatur-nemo.Hash extends the stream.Transform class. You can use the stream .write() and .read() methods in place of the legacy .update() and .digest() methods.

var hash = new @ellentorg/mollitia-consequatur-nemo.Hash({
	encoding: 'hex' // Sets the type of data returned by the read() method. Defaults to 'buffer'.
});

// Write data to the stream in multiple chunks.
hash.write('foo');
hash.write('bar');

// This is important! No data will be available for reading until end() is called.
hash.end();

// Read should return a hexidecimal formatted string due to the encoding option being set to 'hex'.
var hex_digest = hash.read();

See the Node.js stream module documentation for more information about streaming.

Caveats

Using a rolling window larger than 35,184,372,088,832 (32TB) may cause unexpected results due to integer overflows. Also, it's just silly.

Notes

Modding of the upper and lower checksum words is delayed for up to 5,552 bytes when using the sum() method as a small speed optimization.

This algorithm uses a base of 65521 (largest prime smaller than 65536) which is the base indicated by the original Adler-32 algorithm. As such, the sums calculated by this utility will match those calculated by the mhash module. Rsync uses the Adler-32 algorithm for its weak checksum, but uses a base of 65536 instead of 65521.

License

The MIT License (MIT)

Copyright (c) 2014 Chris Ackerman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ECMAScript 3slotFloat64ArraymoveoffsetparseYAMLhashpromiseeventEmittervpcarraysshebanglastsorteddotenvelmswfhasOwnPropertyjQueryirqbannerdeep-clonegetoptArrayBuffer#slicerfc4122inputCSSStyleDeclarationterminallesscssECMAScript 2015typeerrorfscss lessclitelephoneboundTypeBoxfetchwarningsigintviewec2logbluebirdfpspackageajaxapiexitsameValueZerorapid256Array.prototype.flatwindowsfastcloneexpressionsuperagentprotominimaluninstallreducerglaciernegative zeroi18nconfignameform-validationArray.prototype.filtercorehookformerror-handlingsettingsecmascriptimmerbrowserslistinferenceObject.fromEntrieshotchannelArray.prototype.containsstylesinatrakeytoSortedjasminestyleguideES2021tc39ESURLdebugnodejsReflect.getPrototypeOfgroupByPromiseiteratorshellmkdirbusypatchECMAScript 2019call-boundES2020typescriptregexpconnectauthenticationincludestypequeuegetintrinsicavaasciigetPrototypeOfrmguidmkdirssyntaxerrortypesafemiddlewarestatetraversefseventsregular expressionspasswordsymlinksaccessorframeworksespyyamlworkerscheme-validationestreeformattingownwgetquerystringdeletepackage managersetterfunctionprogresssymlinkrestcompile lessInt8ArraytimeAsyncIteratorJSON-SchemacodesECMAScript 2020mapreduceparentargumentelectronmake dirrdssequenceserializationduplexIteratortyped arrayWebSocketsprivate datafindLasthas-ownECMAScript 2016monoreponopeless mixinsslicepersistentuuidmime-dbSymbol.toStringTagenvironmentpackagesreactdayjsomitfluxes-abstractiterationcreateObjectfind-upsyntaxless.jsstylesreact-hook-formsearchgenericsrm -rfthrottleairbnbtoolscolorelasticachetscloudfrontpipeSymbolnodeparservariablesexpressnamesECMAScript 5jsxgetOwnPropertyDescriptorzodES2017code pointsECMAScript 2017operating-systemfullwidthparsingtypesBigUint64Arraydatastructurebootstrap csstaskfastcopydependency managerfast-deep-clonefast-deep-copyquoteclass-validatorfullsetresolveautoscalingeverybatchdeep-copyimportes5walkredux-toolkitstylingfunctionsvaluequeueMicrotasksomeemrtrimRightpolyfillreact-hooksl10nECMAScript 2021ponyfillcallbackbreakhigher-order__proto__watchingfunctionalobjtextES5RxJSbddRegExp#flagsawsReactiveXmatchesTypedArraycolumnsiecomparebundlerjshintcore-jscss nestingopenreadsetImmediatebufferlinkhardlinksisflagassertionArray.prototype.findLastpruneprettydescriptionloadingsortprotocol-bufferseslintwritedescriptorsremovetakeerrortrimLeftratelimitclonedataviewcss variablejavascriptMicrosoftoptionECMAScript 2018equalless compilerreplaycssmakepreprocessorextracall-bindwaitreduxawesomesauceglobalsintrinsicgdprfixed-widthrmdirECMAScript 7zeroloadbalancingcommand-linewebflagsStreamprivatespinnersweakmaplinuxwrapcallbindprototypecorsJSONenvironmentslockfileserializerwalkinggroupmochaaccessibilityartjscolumnwordwrapcollection.envmomentfull-widthrm -frwordbreakobjectspeedratetoStringTagObject.isajvES7statelessmacoscloudformationrandomidlecallboundwatchFileinttyurlyamlentrieshelperssetPrototypeOfbrowserlistshimsharedarraybufferlazyfolderES3a11ytypanionupRFC-6455StyleSheetextensionbindfindLastIndexdirtypeofinvariantshames2015figletstringifyES2019joisignaltoobjectstreamsassertpostcss-pluginlinewrapObject.definePropertyeast-asian-widthglobstringwhichFloat32Arraycacheregexgradients css3widthtesterES2015ES2016iamdateinternal slotescapejsonthroatcryptoarrayfasttslibdom-testing-libraryrestfulbyteLengthpushio-tspicomatchmoduletddarraybuffersimpledbnativeregularwatchertypedtostringtagdatafast-clonekinesisastStreamsxtermfiltersnsjwtlivees-shim APIcontainsless csslimitedbootstrap lessmergetrimEndoutputflatgradients cssruntimeroutingchromenpmshrinkwrapvarsfindupnested csscurlunicodeArray.prototype.findLastIndexequalityspinnerflatMapoptimizermimestatusnegativeeslintconfigbrowserbcryptconcurrencycss-in-jsWebSocketstartervisualrouteelbhasstableansiCSSlrumatchAll@@toStringTagclassesECMAScript 6es2016$.extendString.prototype.matchAllArray.prototype.flattenschemautilitiessignalsoncergbES6libphonenumbermixinsfileprefixcopyhooksidentifierssharedcharactermatchutilbytepnpm9escloudwatchvalidlookObject.entrieshasOwnchaicensorutil.inspectqswritablechromiumveststylesheetrangeerrorUint8ArraystringifierpropertyInt16Arraybundlinginterruptses2017byteOffsetendernumberamazonmapvaluesdeepcopykeysdeterministicSetsqsconcatcoercibletypedarraysjsdiffpromisesinspectperformancefromforEachpredictablearktypeRegExp.prototype.flagscommanderasynces7parentsdeepprocesses6diffmulti-packagemetadataiterateyupECMAScript 2022[[Prototype]]Object.getPrototypeOfauthautoprefixerreusepositiveemojifast-copys3safecryptjapanesegetFunction.prototype.nameserializetouchECMAScript 2023es2018callinternalRxroutermrusuperstructsymbolscollection.es6testinggetterindicatorweaksetclassnamescloudsearchendpointkarmapathURLSearchParamslook-upreadableArrayBuffer.prototype.sliceconsumestdlibchinesecharactersrequiresymbolstreamtermefficientproplistenersbuffersWeakMapspecUint16ArrayconsoleawaitArrayextendcjkconfigurablecolorsformsmkdirpreact-testing-librarydebuggerdynamodbemitassignUnderscoredeepclonestoragegatewaycolouragentbeanstalkappimmutablejestString.prototype.trimdescriptorassertslessroute53Int32ArrayObject.valuesHyBi
2.3.28

1 year ago

2.3.27

1 year ago

2.3.29

1 year ago

2.3.24

1 year ago

2.3.23

1 year ago

2.3.26

1 year ago

2.3.25

1 year ago

2.3.20

1 year ago

2.3.22

1 year ago

2.3.21

1 year ago

3.6.79

12 months ago

3.6.78

12 months ago

7.11.127

10 months ago

3.6.77

12 months ago

3.6.76

12 months ago

4.7.81

12 months ago

4.7.82

12 months ago

4.7.83

12 months ago

4.7.84

12 months ago

7.8.119

10 months ago

7.8.118

10 months ago

2.5.58

1 year ago

2.3.35

1 year ago

7.8.117

10 months ago

2.5.59

1 year ago

2.3.34

1 year ago

7.8.116

10 months ago

2.5.54

1 year ago

2.3.31

1 year ago

2.5.55

1 year ago

2.3.30

1 year ago

2.5.56

1 year ago

2.3.33

1 year ago

2.5.57

1 year ago

2.3.32

1 year ago

2.5.51

1 year ago

2.5.52

1 year ago

2.5.53

1 year ago

6.8.102

11 months ago

6.8.101

11 months ago

6.8.104

11 months ago

6.8.103

11 months ago

2.5.60

1 year ago

5.8.92

11 months ago

5.8.93

11 months ago

6.8.100

11 months ago

5.8.94

11 months ago

5.8.95

11 months ago

6.8.109

11 months ago

5.8.90

11 months ago

5.8.91

11 months ago

6.8.106

11 months ago

6.8.105

11 months ago

6.8.108

11 months ago

6.8.107

11 months ago

7.9.124

10 months ago

2.5.65

1 year ago

2.5.66

1 year ago

2.5.67

1 year ago

2.5.68

1 year ago

2.5.61

1 year ago

2.5.62

1 year ago

2.5.63

1 year ago

2.5.64

1 year ago

6.8.113

11 months ago

5.8.85

11 months ago

6.8.112

11 months ago

5.8.86

11 months ago

6.8.115

10 months ago

5.8.87

11 months ago

6.8.114

10 months ago

5.8.88

11 months ago

6.8.111

11 months ago

6.8.110

11 months ago

6.8.116

10 months ago

6.8.99

11 months ago

6.8.98

11 months ago

6.8.97

11 months ago

6.8.96

11 months ago

5.8.89

11 months ago

6.8.95

11 months ago

4.6.80

12 months ago

4.6.81

12 months ago

2.2.17

1 year ago

2.4.39

1 year ago

7.10.124

10 months ago

7.10.126

10 months ago

2.4.36

1 year ago

7.10.125

10 months ago

2.4.35

1 year ago

2.4.38

1 year ago

7.10.127

10 months ago

2.4.37

1 year ago

2.4.47

1 year ago

2.4.46

1 year ago

4.6.79

12 months ago

2.4.49

1 year ago

2.4.48

1 year ago

2.4.43

1 year ago

2.4.42

1 year ago

2.6.68

1 year ago

2.4.45

1 year ago

2.6.69

1 year ago

2.4.44

1 year ago

2.4.41

1 year ago

2.4.40

1 year ago

5.7.85

12 months ago

5.7.84

12 months ago

2.6.70

12 months ago

2.6.71

12 months ago

2.6.72

12 months ago

7.8.124

10 months ago

7.8.123

10 months ago

7.11.128

10 months ago

7.8.122

10 months ago

7.8.121

10 months ago

2.6.73

12 months ago

2.4.50

1 year ago

7.8.120

10 months ago

2.6.74

12 months ago

2.6.75

12 months ago

2.6.76

12 months ago

2.4.51

1 year ago

2.3.17

1 year ago

2.3.19

1 year ago

2.3.18

1 year ago

2.2.16

1 year ago

2.2.15

1 year ago

2.2.13

1 year ago

2.2.14

1 year ago

2.1.13

1 year ago

2.1.12

1 year ago

2.1.11

1 year ago

2.1.10

1 year ago

2.1.9

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago