fix(core): update

This commit is contained in:
Philipp Kunz 2023-11-24 19:15:41 +01:00
parent 3b05aab39b
commit 9935fe2d3c
5 changed files with 489 additions and 325 deletions

View File

@ -26,7 +26,7 @@
},
"homepage": "https://gitlab.com/push.rocks/smartfile#readme",
"dependencies": {
"@push.rocks/lik": "^6.0.5",
"@push.rocks/lik": "^6.0.12",
"@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartfile-interfaces": "^1.0.7",
"@push.rocks/smarthash": "^3.0.4",
@ -34,11 +34,11 @@
"@push.rocks/smartmime": "^1.0.5",
"@push.rocks/smartpath": "^5.0.11",
"@push.rocks/smartpromise": "^4.0.2",
"@push.rocks/smartrequest": "^2.0.20",
"@push.rocks/smartstream": "^3.0.7",
"@types/fs-extra": "^11.0.3",
"@push.rocks/smartrequest": "^2.0.21",
"@push.rocks/smartstream": "^3.0.30",
"@types/fs-extra": "^11.0.4",
"@types/glob": "^8.1.0",
"@types/js-yaml": "^4.0.8",
"@types/js-yaml": "^4.0.9",
"fs-extra": "^11.1.1",
"glob": "^10.3.10",
"js-yaml": "^4.1.0"
@ -46,9 +46,9 @@
"devDependencies": {
"@git.zone/tsbuild": "^2.1.70",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.81",
"@git.zone/tstest": "^1.0.84",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.10"
"@types/node": "^20.10.0"
},
"files": [
"ts/**/*",

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartfile',
version: '11.0.2',
version: '11.0.3',
description: 'offers smart ways to work with files in nodejs'
}

View File

@ -91,6 +91,12 @@ export class SmartFile extends plugins.smartjson.Smartjson {
});
}
public async fromUrl (urlArg: string) {
const response = await plugins.smartrequest.getBinary(urlArg);
const smartfile = await SmartFile.fromBuffer(urlArg, response.body);
return smartfile;
}
// ========
// INSTANCE
// ========

View File

@ -392,44 +392,50 @@ export const listFileTree = async (
* Watches for file stability before resolving the promise.
*/
export const waitForFileToBeReady = (filePathArg: string): Promise<void> => {
return new Promise((resolve, reject) => {
let lastSize = -1;
let stableCheckTimeout: NodeJS.Timeout | null = null;
return new Promise(async (resolve, reject) => {
let lastFileSize = -1;
let fileIsStable = false;
const clearStableCheckTimeout = () => {
if (stableCheckTimeout) {
clearTimeout(stableCheckTimeout);
stableCheckTimeout = null;
const checkFileStability = async () => {
let currentFileSize: number;
const deferred = plugins.smartpromise.defer();
plugins.fs.stat(filePathArg, (err, stats) => {
if (err) {
fileIsStable = true;
watcher.close();
reject(err);
return;
}
currentFileSize = stats.size;
deferred.resolve();
});
await deferred.promise;
if (currentFileSize === lastFileSize) {
fileIsStable = true;
await plugins.smartdelay.delayFor(100);
resolve();
}
lastFileSize = currentFileSize;
};
const watcher = plugins.fs.watch(filePathArg, (eventType, filename) => {
if (eventType === 'change') {
plugins.fs.stat(filePathArg, (err, stats) => {
if (err) {
watcher.close();
clearStableCheckTimeout();
reject(err);
return;
}
if (stats.size === lastSize) {
clearStableCheckTimeout();
stableCheckTimeout = setTimeout(() => {
watcher.close();
resolve();
}, 5000); // stability duration
} else {
lastSize = stats.size;
}
});
checkFileStability();
}
});
watcher.on('error', (error) => {
clearStableCheckTimeout();
watcher.close();
reject(error);
});
while (!fileIsStable) {
await checkFileStability();
if (!fileIsStable) {
await plugins.smartdelay.delayFor(5000);
}
}
watcher.close();
});
};