2021-12-23 15:27:17 +01:00
|
|
|
/* eslint-disable */
|
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
import { ReadStream } from "fs";
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2021-06-24 10:23:32 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-06-24 10:09:10 +02:00
|
|
|
function extend(who: any, from: any, overwrite = true) {
|
|
|
|
const ownProps = Object.getOwnPropertyNames(Object.getPrototypeOf(from)).concat(Object.keys(from));
|
|
|
|
ownProps.forEach((prop) => {
|
|
|
|
if (prop === "constructor" || from[prop] === undefined) return;
|
|
|
|
if (who[prop] && overwrite) {
|
|
|
|
who[`_${prop}`] = who[prop];
|
|
|
|
}
|
|
|
|
if (typeof from[prop] === "function") who[prop] = from[prop].bind(who);
|
|
|
|
else who[prop] = from[prop];
|
|
|
|
});
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function stob(stream: ReadStream): Promise<Buffer> {
|
2021-06-24 10:09:10 +02:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
const buffers: Buffer[] = [];
|
|
|
|
stream.on("data", buffers.push.bind(buffers));
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
stream.on("end", () => {
|
|
|
|
switch (buffers.length) {
|
|
|
|
case 0:
|
|
|
|
resolve(Buffer.allocUnsafe(0));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
resolve(buffers[0]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
resolve(Buffer.concat(buffers));
|
|
|
|
}
|
|
|
|
});
|
2020-09-28 18:52:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-29 10:57:14 +02:00
|
|
|
export { extend, stob };
|