{"id":13547828,"url":"https://github.com/srijs/rusha","last_synced_at":"2025-05-15T16:01:53.206Z","repository":{"id":7647989,"uuid":"9008640","full_name":"srijs/rusha","owner":"srijs","description":"High-performance pure-javascript SHA1 implementation suitable for large binary data, reaching up to half the native speed.","archived":false,"fork":false,"pushed_at":"2024-06-09T04:34:03.000Z","size":980,"stargazers_count":278,"open_issues_count":8,"forks_count":32,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-14T20:57:33.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://npmjs.org/rusha","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/srijs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-03-25T15:01:07.000Z","updated_at":"2024-11-17T09:01:44.000Z","dependencies_parsed_at":"2024-11-08T03:04:17.352Z","dependency_job_id":"6e7b44b4-441e-40d4-b936-e97c03a60457","html_url":"https://github.com/srijs/rusha","commit_stats":{"total_commits":216,"total_committers":22,"mean_commits":9.818181818181818,"dds":"0.48611111111111116","last_synced_commit":"946fd49d8180d50e1b6ed307e7fdc82a0ae91277"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srijs%2Frusha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srijs%2Frusha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srijs%2Frusha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srijs%2Frusha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srijs","download_url":"https://codeload.github.com/srijs/rusha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374388,"owners_count":22060609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T12:01:01.612Z","updated_at":"2025-05-15T16:01:53.116Z","avatar_url":"https://github.com/srijs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Frameworks and Libs"],"sub_categories":["JavaScript"],"readme":"# Rusha\n\n*A high-performance pure-javascript SHA1 implementation suitable for large binary data.*\n\n[![npm](https://img.shields.io/npm/v/rusha.svg)](https://www.npmjs.com/package/rusha) [![npm](https://img.shields.io/npm/dm/rusha.svg)](https://www.npmjs.com/package/rusha) [![Build Status](https://travis-ci.org/srijs/rusha.svg?branch=master)](https://travis-ci.org/srijs/rusha)\n\n## Installing\n\n### NPM\n\nRusha is available via [npm](http://npmjs.org/):\n\n```\nnpm install rusha\n```\n\n### Bower\n\nRusha is available via [bower](http://twitter.github.com/bower/):\n\n```\nbower install rusha\n```\n\n## Usage\n\nIt is highly recommended to run CPU-intensive tasks in a [Web Worker](http://developer.mozilla.org/en-US/docs/DOM/Using_web_workers). To do so, just follow the instructions on [_Using the Rusha Worker_](#using-the-rusha-worker).\n\nIf you have a good reason not to use Web Workers, follow the instructions on [_Using the Rusha Hash API_](#using-the-rusha-hash-api) instead.\n\n### Using the Rusha Worker\n\n#### Spawning workers\n\nYou can create a new worker in two ways. The preferred way is using `Rusha.createWorker()`, which spawns a webworker containing the hashing logic, and returns back a `Worker` object:\n\n```js\nconst worker = Rusha.createWorker();\n```\n\nIf for some reason this does not work for you, you can also just point the `Worker` constructor\nat `rusha.js` or `rusha.min.js`, like so:\n\n```js\nconst worker = new Worker(\"dist/rusha.min.js\");\n```\n\n\u003e _**Note**: In order to make the latter work, Rusha will by default subscribe to incoming messages\nwhen it finds itself inside a worker context. This can lead to problems when you would like to use Rusha as a library inside a web worker, but still have control over the messaging. To disable this behaviour, you can call `Rusha.disableWorkerBehaviour()` from within the worker._\n\n#### Communicating with the worker\n\nYou can send your instance of the web worker messages in the format `{id: jobid, data: dataobject}`. The worker then sends back a message in the format `{id: jobid, hash: hash}`, were jobid is the id of the job previously received and hash is the hash of the data-object you passed, be it a `Blob`, `Array`, `Buffer`, `ArrayBuffer` or `String`\n\n### Using the Rusha Hash API\n\nThe Rusha `Hash` API is inspired by the [Node.js `Hash` API](https://nodejs.org/api/crypto.html#crypto_class_hash).\n\n#### Examples\n\n##### Simple usage\n\n```js\nconst hexHash = Rusha.createHash().update('I am Rusha').digest('hex'); \n```\n\n##### Incremental usage\n\n```js\nconst hash = Rusha.createHash(); \nhash.update('I am');\nhash.update(' Rusha');\nconst hexHash = rusha.digest('hex');\n```\n\n#### Reference\n\nYou instantiate a new Hash object by calling `Rusha.createHash()`.\n\n##### Methods\n\n- `update(data)`: Update the hash state with the given `data`, which can be a binary `String`, `Buffer`, `Array` or `ArrayBuffer`.\n- `digest([encoding])`: Calculates the digest of all of the data passed to be hashed. The `encoding` can be `'hex'` or undefined. If `encoding` is provided a string will be returned; otherwise an `ArrayBuffer` is returned.\n\n\u003e _**Note**: Due to its synchronous nature, `Hash#update` does not accept data of type `Blob`. If you need to work with `Blob`s, you can either use the [Rusha Worker](#using-the-rusha-worker), or use [`FileReader#readAsArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer) to read the contents of the `Blob`, and then invoke `Hash#update` with the `ArrayBuffer` that was returned._\n\n##### Properties\n\n- `state` (getter and setter): Allows getting and setting the internal hashing state.\n\n### Using the Rusha Object (DEPRECATED)\n\nThe Rusha Object API is deprecated, and is only documented here for older code bases that might still be using it.\n\nYou should be using the `Hash` API instead, which is documented above.\n\n#### Examples\n\n##### Normal usage\n\n```js\nconst rusha = new Rusha();\nconst hexHash = rusha.digest('I am Rusha'); \n```\n\n##### Incremental usage\n\n```js\nconst rusha = new Rusha();\nrusha.resetState();\nrusha.append('I am');\nrusha.append(' Rusha');\nconst hexHash = rusha.end();\n```\n\n#### Reference\n\nYour instantiate a new Rusha object by doing `new Rusha()`. When created, it provides the following methods:\n\n- `digest(d)`: Create a hex digest from data of the three kinds mentioned below, or throw and error if the type is unsupported.\n- `digestFromString(s)`: Create a hex digest from a binary `String`. A binary string is expected to only contain characters whose charCode \u003c 256.\n- `digestFromBuffer(b)`: Create a hex digest from a `Buffer` or `Array`. Both are expected to only contain elements \u003c 256.\n- `digestFromArrayBuffer(a)`: Create a hex digest from an `ArrayBuffer` object.\n- `rawDigest(d)`: Behaves just like #digest(d), except that it returns the digest as an Int32Array of size 5.\n- `resetState()`: Resets the internal state of the computation.\n- `append(d)`: Appends a binary `String`, `Buffer`, `Array`, `ArrayBuffer` or `Blob`.\n- `setState(state)`: Sets the internal computation state. See: getState().\n- `setState()`: Returns an object representing the internal computation state. You can pass this state to setState(). This feature is useful to resume an incremental sha.\n- `end()`: Finishes the computation of the sha, returning a hex digest.\n- `rawEnd()`: Behaves just like #end(), except that it returns the digest as an Int32Array of size 5.\n\n## Development\n\n* Download npm dependencies with `npm install`\n* Make changes to the files in `src/`\n* Build with `npm run build`\n* Run tests with `npm test`\n\n## Benchmarks\n\nTested were my Rusha implementation, the sha1.js implementation by [P. A. Johnston](http://pajhome.org.uk/crypt/md5/sha1.html), Tim Caswell's [Cifre](http://github.com/openpeer/cifre) and the Node.JS native implementation.\n\nIf you want to check the performance for yourself in your own browser, I compiled a [JSPerf Page](http://jsperf.com/rusha/13).\n\nA normalized estimation based on the best results for each implementation, smaller is better:\n![rough performance graph](http://srijs.github.io/rusha/bench/unscientific01.png)\n\nResults per Implementation and Platform:\n![performance chart](https://docs.google.com/spreadsheet/oimg?key=0Ag9CYh5kHpegdDB1ZG16WU1xVFgxdjRuQUVwQXRnWVE\u0026oid=1\u0026zx=pcatr2aits9)\n\nAll tests were performed on a MacBook Air 1.7 GHz Intel Core i5 and 4 GB 1333 MHz DDR3.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrijs%2Frusha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrijs%2Frusha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrijs%2Frusha/lists"}