text: import { fsCreateReadStream } from "./fsCreateReadStream";
  import { HashCalculator } from "./HashCalculator";
  import { isFileStream } from "./isFileStream";
  export var readableStreamHasher = function (hashCtor, readableStream) {
      if (!isFileStream(readableStream) && readableStream.readableFlowing !== null) {
          throw new Error("Unable to calculate hash for flowing readable stream");
      }
      var streamToPipe = isFileStream(readableStream) ? fsCreateReadStream(readableStream) : readableStream;
      var hash = new hashCtor();
      var hashCalculator = new HashCalculator(hash);
      streamToPipe.pipe(hashCalculator);
      return new Promise(function (resolve, reject) {
          streamToPipe.on("error", function (err) {
              hashCalculator.end();
              reject(err);
          });
          hashCalculator.on("error", reject);
          hashCalculator.on("finish", function () {
              hash.digest().then(resolve).catch(reject);
          });
      });
  };
  