{"library":"spark-md5","title":"SparkMD5","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install spark-md5"],"cli":null},"imports":["import SparkMD5 from 'spark-md5';","import SparkMD5 from 'spark-md5';\nconst sparkAB = new SparkMD5.ArrayBuffer();","import SparkMD5 from 'spark-md5';\nconst hexHash = SparkMD5.hash('your string');"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/satazor/js-spark-md5","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/spark-md5","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"document.getElementById('file').addEventListener('change', function () {\n    var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,\n        file = this.files[0],\n        chunkSize = 2097152,                             // Read in chunks of 2MB\n        chunks = Math.ceil(file.size / chunkSize),\n        currentChunk = 0,\n        spark = new SparkMD5.ArrayBuffer(),\n        fileReader = new FileReader();\n\n    fileReader.onload = function (e) {\n        console.log('read chunk nr', currentChunk + 1, 'of', chunks);\n        spark.append(e.target.result);                   // Append array buffer\n        currentChunk++;\n\n        if (currentChunk < chunks) {\n            loadNext();\n        } else {\n            console.log('finished loading');\n            console.info('computed hash', spark.end());  // Compute hash\n        }\n    };\n\n    fileReader.onerror = function () {\n        console.warn('oops, something went wrong.');\n    };\n\n    function loadNext() {\n        var start = currentChunk * chunkSize,\n            end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;\n\n        fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));\n    }\n\n    loadNext();\n});\n","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}