Open linojon opened 1 year ago
Currently there is no such option and I think this is outside of the scope of this library. The problem with it, is that for progress calculation you need to first scan all the files to be able to calculate total size, what if implemented in the library will make operation slower for everybody, even if you don't need this option.
That being said, I think it can be coded pretty reasonably with the primitives of this library. Here is very primitive attempt (that I didn't run, so probably contains bugs).
let fileSizes = {};
let totalSize = 0;
let filesToCopy = jetpack.find("my_dir", {
filter: (inspectObj) => {
fileSizes[inspectObj.absolutePath] = inspectObj.size;
totalSize += inspectObj.size;
return true;
}
});
let index = 0;
let alreadyCopiedSize = 0;
const copyFile = () => {
let path = filesToCopy[index];
jetpack.copyAsync(path).then(() => {
alreadyCopiedSize += fileSizes[path];
let progress = alreadyCopiedSize / totalSize;
console.log(progress);
index += 1;
if (index < filesToCopy.length) {
copyFile();
}
});
}
I'm looking for a way to provide a progress bar, especially copying large files and directories. It could also be useful on inspectTree (with md5). Is there a way to do that with this package currently?