SparkMD5 is a JavaScript library providing a fast and efficient implementation of the MD5 hashing algorithm. Currently at version 3.0.2, it offers both normal (static `.hash()` method) and incremental hashing capabilities (instance-based `.append()` and `.end()`), making it well-suited for processing large amounts of data, such as files in chunks. Its core differentiators include optimized performance based on the JKM md5 library, robust UTF8 string conversion, and documented fixes for overflow issues when hashing extensive datasets in previous versions. It supports ArrayBuffers and integrates seamlessly into CommonJS and AMD environments, functioning effectively in both browser and Node.js contexts, though it is particularly highlighted for browser usage. The library emphasizes memory efficiency for large file operations through its incremental API, making it ideal for client-side file uploads or large data processing.
npm install spark-md5Verified import paths — ran on the pinned version, not inferred.
Demonstrates how to incrementally hash a large file in a web browser using ArrayBuffers and the File API, splitting the file into chunks to manage memory efficiently during the hashing process.
Upgrade to SparkMD5 version 3.x or later to ensure correct computations for large data sets. Always test hash consistency after major version upgrades, especially when dealing with critical data integrity.
For general string input, always use `SparkMD5#append(str)` which correctly handles UTF-8 encoding. Only use `appendBinary(str)` if you are absolutely certain the input `str` is a true binary string and not a standard UTF-8 encoded string.
For Chrome, launch the browser with the `--allow-file-access-from-files` flag. Alternatively, serve your HTML file via a local web server (e.g., `http-server`, `serve`, or a simple Python web server) to avoid these browser-level security restrictions.
For direct, non-incremental hashing of a single string, call `SparkMD5.hash('your string')`. For incremental hashing, create an instance: `const spark = new SparkMD5(); spark.append('...'); spark.end();`Ensure your import statement matches your module system: `import SparkMD5 from 'spark-md5';` for ES Modules (often with `esModuleInterop: true` in TypeScript) or `const SparkMD5 = require('spark-md5');` for CommonJS. If using TypeScript, check your `tsconfig.json` for `allowSyntheticDefaultImports` and `esModuleInterop` options.Ensure your target web browser or runtime environment supports the necessary File and Blob APIs. For extremely old browsers, consider using polyfills for these APIs if available, or specify a more modern browser as a minimum requirement for your application.
No dependency data recorded yet.