Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
transform: (read: ReadStream, write: WriteStream) => {
// Insert Progress report in ncp stream
// For every file in ncp
var id = progressPerFileStack.length;
progressPerFileStack[id] = 0;
var str = progress({
time: 100
}).on("progress", progress => {
progressPerFileStack[id] = progress.transferred;
calcProgress();
});
read.pipe(str).pipe(write);
}
};
const extractEntry = async (
entry: yauzl.Entry,
err: Error,
src: NodeJS.ReadableStream
) => {
if (err) {
throw err;
}
const entryPath = join(destination, entry.fileName);
await sf.mkdirp(dirname(entryPath));
const dst = createWriteStream(entryPath);
const progressStream = progress({
length: entry.uncompressedSize,
time: 100,
});
let progressFactor = entry.compressedSize / zipfile.fileSize;
progressStream.on("progress", info => {
opts.onProgress({
progress: progressOffset + (info.percentage / 100) * progressFactor,
});
});
progressStream.pipe(dst);
src.pipe(progressStream);
await sf.promised(dst);
progressOffset += progressFactor;
await sf.chmod(entryPath, 0o755);
const fileBuffer = await sf.readFile(entryPath, { encoding: null });
sink: () => {
progressStream = progress({ length: totalSize, time: 500 });
progressStream.on("progress", info => {
onProgress({
progress: info.percentage / 100,
eta: info.eta,
bps: info.speed,
doneBytes: (info.percentage / 100) * totalSize,
totalBytes: totalSize,
});
logger.info(
`${info.percentage.toFixed(1)}% done, eta ${info.eta.toFixed(
1
)}s @ ${fileSize(info.speed)}/s`
);
});
progressStream.pipe(fileSink);
return progressStream;
transform: (read, write) => {
var str = progress({
length: fs.statSync(read.path).size,
time: 700
});
str.on('progress', (progress) => {
process.send({
type: t.FS_WRITE_PROGRESS,
payload: {
id: id,
file: {
source: read.path,
destination: write.path,
progress: progress}
}
})
})
read.pipe(str).pipe(write)
constructor({ stream, onProgress }) {
check(stream, Stream);
this.stream = stream;
if (onProgress) {
const options = {
time: 1000,
speed: 1000,
};
const progressStream = createProgressStream(options, onProgress);
this.stream = this.stream.pipe(progressStream);
}
}