open-next-cdk
Version:
Deploy a NextJS app using OpenNext packaging to serverless AWS using CDK
24 lines (23 loc) • 895 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readableStreamHasher = void 0;
const HashCalculator_1 = require("./HashCalculator");
const readableStreamHasher = (hashCtor, readableStream) => {
if (readableStream.readableFlowing !== null) {
throw new Error("Unable to calculate hash for flowing readable stream");
}
const hash = new hashCtor();
const hashCalculator = new HashCalculator_1.HashCalculator(hash);
readableStream.pipe(hashCalculator);
return new Promise((resolve, reject) => {
readableStream.on("error", (err) => {
hashCalculator.end();
reject(err);
});
hashCalculator.on("error", reject);
hashCalculator.on("finish", () => {
hash.digest().then(resolve).catch(reject);
});
});
};
exports.readableStreamHasher = readableStreamHasher;