1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const crypto = require('crypto'); 9const Stream = require('stream'); 10 11const hasher1 = crypto.createHash('sha256'); 12const hasher2 = crypto.createHash('sha256'); 13 14// Calculate the expected result. 15hasher1.write(Buffer.from('hello world')); 16hasher1.end(); 17 18const expected = hasher1.read().toString('hex'); 19 20class OldStream extends Stream { 21 constructor() { 22 super(); 23 this.readable = true; 24 } 25} 26 27const stream = new OldStream(); 28 29stream.pipe(hasher2).on('finish', common.mustCall(function() { 30 const hash = hasher2.read().toString('hex'); 31 assert.strictEqual(hash, expected); 32})); 33 34stream.emit('data', Buffer.from('hello')); 35stream.emit('data', Buffer.from(' world')); 36stream.emit('end'); 37