const crypto = require('crypto');
// Simulate processing a large file in chunks
function processLargeDataIncrementally() {
// Create a hash object
const hash = crypto.createHash('sha256');
// Simulate reading data in chunks
const totalChunks = 10;
console.log(`Processing data in ${totalChunks} chunks...`);
for (let i = 0; i < totalChunks; i++) {
// In a real scenario, this would be data read from a file or stream
const chunk = `Chunk ${i + 1} of data with some random content: ${crypto.randomBytes(10).toString('hex')}`;
console.log(`Processing chunk ${i + 1}/${totalChunks}, size: ${chunk.length} bytes`);
// Update the hash with this chunk
hash.update(chunk);
}
// Calculate final hash after all chunks are processed
const finalHash = hash.digest('hex');
console.log('Final SHA-256 hash:', finalHash);
}
// Run the example
processLargeDataIncrementally();