11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciif (!common.hasCrypto)
51cb0ef41Sopenharmony_ci  common.skip('missing crypto');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ciconst crypto = require('crypto');
91cb0ef41Sopenharmony_ciconst Stream = require('stream');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst hasher1 = crypto.createHash('sha256');
121cb0ef41Sopenharmony_ciconst hasher2 = crypto.createHash('sha256');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci// Calculate the expected result.
151cb0ef41Sopenharmony_cihasher1.write(Buffer.from('hello world'));
161cb0ef41Sopenharmony_cihasher1.end();
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst expected = hasher1.read().toString('hex');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciclass OldStream extends Stream {
211cb0ef41Sopenharmony_ci  constructor() {
221cb0ef41Sopenharmony_ci    super();
231cb0ef41Sopenharmony_ci    this.readable = true;
241cb0ef41Sopenharmony_ci  }
251cb0ef41Sopenharmony_ci}
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciconst stream = new OldStream();
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_cistream.pipe(hasher2).on('finish', common.mustCall(function() {
301cb0ef41Sopenharmony_ci  const hash = hasher2.read().toString('hex');
311cb0ef41Sopenharmony_ci  assert.strictEqual(hash, expected);
321cb0ef41Sopenharmony_ci}));
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_cistream.emit('data', Buffer.from('hello'));
351cb0ef41Sopenharmony_cistream.emit('data', Buffer.from(' world'));
361cb0ef41Sopenharmony_cistream.emit('end');
37