初始化环境文件
This commit is contained in:
35
node_modules/@smithy/util-stream/dist-es/checksum/createChecksumStream.browser.js
generated
vendored
Normal file
35
node_modules/@smithy/util-stream/dist-es/checksum/createChecksumStream.browser.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import { toBase64 } from "@smithy/util-base64";
|
||||
import { isReadableStream } from "../stream-type-check";
|
||||
import { ChecksumStream } from "./ChecksumStream.browser";
|
||||
export const createChecksumStream = ({ expectedChecksum, checksum, source, checksumSourceLocation, base64Encoder, }) => {
|
||||
if (!isReadableStream(source)) {
|
||||
throw new Error(`@smithy/util-stream: unsupported source type ${source?.constructor?.name ?? source} in ChecksumStream.`);
|
||||
}
|
||||
const encoder = base64Encoder ?? toBase64;
|
||||
if (typeof TransformStream !== "function") {
|
||||
throw new Error("@smithy/util-stream: unable to instantiate ChecksumStream because API unavailable: ReadableStream/TransformStream.");
|
||||
}
|
||||
const transform = new TransformStream({
|
||||
start() { },
|
||||
async transform(chunk, controller) {
|
||||
checksum.update(chunk);
|
||||
controller.enqueue(chunk);
|
||||
},
|
||||
async flush(controller) {
|
||||
const digest = await checksum.digest();
|
||||
const received = encoder(digest);
|
||||
if (expectedChecksum !== received) {
|
||||
const error = new Error(`Checksum mismatch: expected "${expectedChecksum}" but received "${received}"` +
|
||||
` in response header "${checksumSourceLocation}".`);
|
||||
controller.error(error);
|
||||
}
|
||||
else {
|
||||
controller.terminate();
|
||||
}
|
||||
},
|
||||
});
|
||||
source.pipeThrough(transform);
|
||||
const readable = transform.readable;
|
||||
Object.setPrototypeOf(readable, ChecksumStream.prototype);
|
||||
return readable;
|
||||
};
|
||||
Reference in New Issue
Block a user