Initial
This commit is contained in:
17
resources/app/node_modules/@smithy/hash-stream-node/dist-es/HashCalculator.js
generated
vendored
Normal file
17
resources/app/node_modules/@smithy/hash-stream-node/dist-es/HashCalculator.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { toUint8Array } from "@smithy/util-utf8";
|
||||
import { Writable } from "stream";
|
||||
export class HashCalculator extends Writable {
|
||||
constructor(hash, options) {
|
||||
super(options);
|
||||
this.hash = hash;
|
||||
}
|
||||
_write(chunk, encoding, callback) {
|
||||
try {
|
||||
this.hash.update(toUint8Array(chunk));
|
||||
}
|
||||
catch (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback();
|
||||
}
|
||||
}
|
||||
24
resources/app/node_modules/@smithy/hash-stream-node/dist-es/fileStreamHasher.js
generated
vendored
Normal file
24
resources/app/node_modules/@smithy/hash-stream-node/dist-es/fileStreamHasher.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createReadStream } from "fs";
|
||||
import { HashCalculator } from "./HashCalculator";
|
||||
export const fileStreamHasher = (hashCtor, fileStream) => new Promise((resolve, reject) => {
|
||||
if (!isReadStream(fileStream)) {
|
||||
reject(new Error("Unable to calculate hash for non-file streams."));
|
||||
return;
|
||||
}
|
||||
const fileStreamTee = createReadStream(fileStream.path, {
|
||||
start: fileStream.start,
|
||||
end: fileStream.end,
|
||||
});
|
||||
const hash = new hashCtor();
|
||||
const hashCalculator = new HashCalculator(hash);
|
||||
fileStreamTee.pipe(hashCalculator);
|
||||
fileStreamTee.on("error", (err) => {
|
||||
hashCalculator.end();
|
||||
reject(err);
|
||||
});
|
||||
hashCalculator.on("error", reject);
|
||||
hashCalculator.on("finish", function () {
|
||||
hash.digest().then(resolve).catch(reject);
|
||||
});
|
||||
});
|
||||
const isReadStream = (stream) => typeof stream.path === "string";
|
||||
2
resources/app/node_modules/@smithy/hash-stream-node/dist-es/index.js
generated
vendored
Normal file
2
resources/app/node_modules/@smithy/hash-stream-node/dist-es/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./fileStreamHasher";
|
||||
export * from "./readableStreamHasher";
|
||||
19
resources/app/node_modules/@smithy/hash-stream-node/dist-es/readableStreamHasher.js
generated
vendored
Normal file
19
resources/app/node_modules/@smithy/hash-stream-node/dist-es/readableStreamHasher.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { HashCalculator } from "./HashCalculator";
|
||||
export 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(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);
|
||||
});
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user