@d0paminedriven/fs 6.3.0 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -0
- package/dist/{chunk-C6AZRX7V.js → chunk-O4BKLMFV.js} +2 -2
- package/dist/{chunk-XHN56MDK.js → chunk-QBG7TFHM.js} +5 -2
- package/dist/{chunk-NGBMZGGU.js → chunk-Y3TLKN7F.js} +61 -5
- package/dist/fs/index.cjs +188 -4
- package/dist/fs/index.d.cts +49 -6
- package/dist/fs/index.d.ts +49 -6
- package/dist/fs/index.js +4 -3
- package/dist/index.cjs +185 -129
- package/dist/index.js +3 -3
- package/dist/mime/index.cjs +129 -1
- package/dist/mime/index.d.cts +4 -3
- package/dist/mime/index.d.ts +4 -3
- package/dist/mime/index.js +3 -2
- package/dist/url/index.cjs +131 -1
- package/dist/url/index.d.cts +6 -1
- package/dist/url/index.d.ts +6 -1
- package/dist/url/index.js +2 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -98,8 +98,16 @@ fs.mimeToExt("image/jpeg"); // "jpg" (returns common extension)
|
|
|
98
98
|
// Write to tmp with automatic cleanup
|
|
99
99
|
const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
|
|
100
100
|
|
|
101
|
+
// Generate unique tmp filenames
|
|
102
|
+
const uniqueName = fs.uniqueTmpName("upload", "bin");
|
|
103
|
+
// Result: "upload-1701234567890-x7y8z9.bin"
|
|
104
|
+
|
|
101
105
|
// Scan tmp directory (non-recursive by default to avoid permission issues)
|
|
102
106
|
const tmpFiles = fs.scanTmp("session-"); // Find all session files
|
|
107
|
+
const regexFiles = fs.scanTmp(/\.json$/); // Regex pattern support
|
|
108
|
+
|
|
109
|
+
// Remove individual tmp files with precision
|
|
110
|
+
fs.rmTmpFile("session-abc123.json"); // Targeted single file removal
|
|
103
111
|
|
|
104
112
|
// Extract files from tmp to permanent location
|
|
105
113
|
fs.extractFromTmp("processed-", "./output", {
|
|
@@ -108,6 +116,12 @@ fs.extractFromTmp("processed-", "./output", {
|
|
|
108
116
|
|
|
109
117
|
// Cleanup old tmp files
|
|
110
118
|
fs.cleanupTmp("cache-", 60 * 60 * 1000); // Remove files older than 1 hour
|
|
119
|
+
|
|
120
|
+
// Async generator for batch removal with progress tracking
|
|
121
|
+
for await (const progress of fs.cleanTmpGenerator("upload-", 20)) {
|
|
122
|
+
// Process files in batches of 20 with real-time progress
|
|
123
|
+
console.log(`Batch ${progress.batchNumber}/${progress.totalBatches}`);
|
|
124
|
+
}
|
|
111
125
|
```
|
|
112
126
|
|
|
113
127
|
### 5. The Legendary `withWs` Method
|
|
@@ -190,6 +204,59 @@ async function processUpload(fileBuffer: Buffer, userId: string) {
|
|
|
190
204
|
}
|
|
191
205
|
```
|
|
192
206
|
|
|
207
|
+
### Advanced Tmp Management
|
|
208
|
+
|
|
209
|
+
#### Granular Single File Removal
|
|
210
|
+
```typescript
|
|
211
|
+
const fs = new Fs(process.cwd());
|
|
212
|
+
|
|
213
|
+
// Create some tmp files
|
|
214
|
+
const tmpFile1 = fs.uniqueTmpName("session", "json");
|
|
215
|
+
const tmpFile2 = fs.uniqueTmpName("cache", "dat");
|
|
216
|
+
fs.writeTmp(tmpFile1, JSON.stringify({ user: "123" }));
|
|
217
|
+
fs.writeTmp(tmpFile2, Buffer.from("cached data"));
|
|
218
|
+
|
|
219
|
+
// Remove a specific tmp file
|
|
220
|
+
fs.rmTmpFile(tmpFile1); // Removes only session-*.json file
|
|
221
|
+
|
|
222
|
+
// Or find and remove specific files
|
|
223
|
+
const sessionFiles = fs.scanTmp("session");
|
|
224
|
+
sessionFiles.forEach(file => fs.rmTmpFile(file));
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### Batch Removal with Progress Tracking
|
|
228
|
+
```typescript
|
|
229
|
+
async function cleanupWithProgress() {
|
|
230
|
+
const fs = new Fs(process.cwd());
|
|
231
|
+
|
|
232
|
+
// Clean tmp files in batches with real-time progress
|
|
233
|
+
for await (const progress of fs.cleanTmpGenerator("upload-", 25)) {
|
|
234
|
+
if (progress.action === 'removing') {
|
|
235
|
+
console.log(`Processing batch ${progress.batchNumber}/${progress.totalBatches}`);
|
|
236
|
+
console.log(`Files in batch: ${progress.batch.length}`);
|
|
237
|
+
} else if (progress.action === 'batch-complete') {
|
|
238
|
+
console.log(`Batch complete! Removed: ${progress.totalRemoved}`);
|
|
239
|
+
console.log(`Remaining: ${progress.remaining}`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Using regex patterns for more complex matching
|
|
245
|
+
async function cleanupPatterns() {
|
|
246
|
+
const fs = new Fs(process.cwd());
|
|
247
|
+
|
|
248
|
+
// Match multiple patterns with regex
|
|
249
|
+
const pattern = /(session|cache|upload)-.*/;
|
|
250
|
+
|
|
251
|
+
for await (const progress of fs.cleanTmpGenerator(pattern, 50)) {
|
|
252
|
+
// Process large batches of 50 files at a time
|
|
253
|
+
if (progress.action === 'batch-complete') {
|
|
254
|
+
console.log(`Batch ${progress.batchNumber}: Removed ${progress.batchSize} files`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
193
260
|
### Build-Time Asset Generation
|
|
194
261
|
|
|
195
262
|
```typescript
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UrlService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QBG7TFHM.js";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
6
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -304,4 +304,4 @@ export {
|
|
|
304
304
|
mimeToExt,
|
|
305
305
|
MimeService
|
|
306
306
|
};
|
|
307
|
-
//# sourceMappingURL=chunk-
|
|
307
|
+
//# sourceMappingURL=chunk-O4BKLMFV.js.map
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UtilsService
|
|
3
|
+
} from "./chunk-IUGBPDQJ.js";
|
|
1
4
|
import {
|
|
2
5
|
__name
|
|
3
6
|
} from "./chunk-7QVYU63E.js";
|
|
4
7
|
|
|
5
8
|
// src/url/index.ts
|
|
6
|
-
var UrlService = class {
|
|
9
|
+
var UrlService = class extends UtilsService {
|
|
7
10
|
static {
|
|
8
11
|
__name(this, "UrlService");
|
|
9
12
|
}
|
|
@@ -27,4 +30,4 @@ var UrlService = class {
|
|
|
27
30
|
export {
|
|
28
31
|
UrlService
|
|
29
32
|
};
|
|
30
|
-
//# sourceMappingURL=chunk-
|
|
33
|
+
//# sourceMappingURL=chunk-QBG7TFHM.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MimeService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-O4BKLMFV.js";
|
|
4
4
|
import {
|
|
5
5
|
unitsObj
|
|
6
6
|
} from "./chunk-MXEE2WS7.js";
|
|
@@ -651,7 +651,6 @@ var Fs = class extends MimeService {
|
|
|
651
651
|
writeTmp(filename, data, options) {
|
|
652
652
|
const fullPath = resolve(this.tmpDir, filename);
|
|
653
653
|
Promise.resolve(this.withWs(fullPath, data, options));
|
|
654
|
-
return fullPath;
|
|
655
654
|
}
|
|
656
655
|
/**
|
|
657
656
|
* Read a file from the tmp directory
|
|
@@ -695,9 +694,11 @@ var Fs = class extends MimeService {
|
|
|
695
694
|
if (!pattern) {
|
|
696
695
|
return tmpContents;
|
|
697
696
|
}
|
|
697
|
+
if (typeof pattern === "string") {
|
|
698
|
+
return tmpContents.filter((t) => t.includes(pattern));
|
|
699
|
+
}
|
|
698
700
|
return tmpContents.filter((path) => {
|
|
699
|
-
|
|
700
|
-
return filename.includes(pattern) || path.startsWith(pattern);
|
|
701
|
+
return pattern.test(path);
|
|
701
702
|
});
|
|
702
703
|
}
|
|
703
704
|
/**
|
|
@@ -783,6 +784,10 @@ var Fs = class extends MimeService {
|
|
|
783
784
|
}
|
|
784
785
|
return removed;
|
|
785
786
|
}
|
|
787
|
+
rmTmpFile(filename) {
|
|
788
|
+
const tmpPath = resolve(this.tmpDir, filename);
|
|
789
|
+
this.rmFile(tmpPath);
|
|
790
|
+
}
|
|
786
791
|
/**
|
|
787
792
|
* Generate a unique tmp filename with optional prefix
|
|
788
793
|
* @param prefix Optional prefix for the filename
|
|
@@ -801,9 +806,60 @@ var Fs = class extends MimeService {
|
|
|
801
806
|
const parts = [prefix ?? "tmp", timestamp, random].join("-");
|
|
802
807
|
return extension ? `${parts}.${extension}` : parts;
|
|
803
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Async generator for cleaning tmp files with batched removal
|
|
811
|
+
* @param pattern Pattern to match files for deletion
|
|
812
|
+
* @param batchSize Number of files to remove per batch (default 10)
|
|
813
|
+
* @yields Progress information during cleanup
|
|
814
|
+
* @returns Final cleanup summary
|
|
815
|
+
* @example
|
|
816
|
+
* ```ts
|
|
817
|
+
* const fs = new Fs(process.cwd());
|
|
818
|
+
* // Clean up with progress tracking
|
|
819
|
+
* for await (const progress of fs.cleanTmpGenerator("session-", 25)) {
|
|
820
|
+
* console.log(progress);
|
|
821
|
+
* }
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
824
|
+
async *cleanTmpGenerator(pattern, batchSize = 10) {
|
|
825
|
+
const files = this.scanTmp(pattern);
|
|
826
|
+
const batches = await this.arrToArrOfArrs({
|
|
827
|
+
arrToFragment: files,
|
|
828
|
+
arrOfArrsAggregator: [],
|
|
829
|
+
interval: batchSize
|
|
830
|
+
});
|
|
831
|
+
let totalRemoved = 0;
|
|
832
|
+
for (const [index, batch] of batches.entries()) {
|
|
833
|
+
yield {
|
|
834
|
+
action: "removing",
|
|
835
|
+
batch: [...batch],
|
|
836
|
+
batchNumber: index + 1,
|
|
837
|
+
totalBatches: batches.length,
|
|
838
|
+
totalFound: files.length,
|
|
839
|
+
removed: totalRemoved
|
|
840
|
+
};
|
|
841
|
+
for (const file of batch) {
|
|
842
|
+
this.rmTmpFile(file);
|
|
843
|
+
totalRemoved++;
|
|
844
|
+
}
|
|
845
|
+
yield {
|
|
846
|
+
action: "batch-complete",
|
|
847
|
+
batchNumber: index + 1,
|
|
848
|
+
batchSize: batch.length,
|
|
849
|
+
totalRemoved,
|
|
850
|
+
remaining: files.length - totalRemoved
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
return {
|
|
854
|
+
action: "complete",
|
|
855
|
+
totalRemoved,
|
|
856
|
+
totalBatches: batches.length,
|
|
857
|
+
pattern: pattern.toString()
|
|
858
|
+
};
|
|
859
|
+
}
|
|
804
860
|
};
|
|
805
861
|
|
|
806
862
|
export {
|
|
807
863
|
Fs
|
|
808
864
|
};
|
|
809
|
-
//# sourceMappingURL=chunk-
|
|
865
|
+
//# sourceMappingURL=chunk-Y3TLKN7F.js.map
|
package/dist/fs/index.cjs
CHANGED
|
@@ -43,8 +43,136 @@ var dotenv = __toESM(require("dotenv"), 1);
|
|
|
43
43
|
var import_dotenv_expand = __toESM(require("dotenv-expand"), 1);
|
|
44
44
|
var import_sharp = __toESM(require("sharp"), 1);
|
|
45
45
|
|
|
46
|
+
// src/utils/index.ts
|
|
47
|
+
var UtilsService = class {
|
|
48
|
+
static {
|
|
49
|
+
__name(this, "UtilsService");
|
|
50
|
+
}
|
|
51
|
+
chunkArray(arr, maxChunkLength) {
|
|
52
|
+
const chunks = Array.of();
|
|
53
|
+
let currentChunkLength = 0;
|
|
54
|
+
let currentChunk = Array.of();
|
|
55
|
+
for (const [index, val] of arr.entries()) {
|
|
56
|
+
if (val.length + currentChunkLength >= maxChunkLength) {
|
|
57
|
+
if (currentChunk.length) {
|
|
58
|
+
chunks.push(currentChunk);
|
|
59
|
+
}
|
|
60
|
+
currentChunkLength = val.length;
|
|
61
|
+
currentChunk = [val];
|
|
62
|
+
} else {
|
|
63
|
+
currentChunk.push(val);
|
|
64
|
+
currentChunkLength += val.length + 1;
|
|
65
|
+
}
|
|
66
|
+
if (arr.length === index + 1) {
|
|
67
|
+
chunks.push(currentChunk);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return chunks.length ? chunks : [arr];
|
|
71
|
+
}
|
|
72
|
+
b64ToBlob(b64Data) {
|
|
73
|
+
{
|
|
74
|
+
const sliceSize = 512;
|
|
75
|
+
const typeMatch = /^data:((?:image|application|haptics|video|text|font|model|audio|multipart)\/[A-Za-z0-9+-.]+(?:;[^,]+)*);base64,(.+)$/i.exec(
|
|
76
|
+
b64Data
|
|
77
|
+
);
|
|
78
|
+
if (!typeMatch) {
|
|
79
|
+
throw new Error(`${b64Data} is not a valid data Url`);
|
|
80
|
+
}
|
|
81
|
+
const type = typeMatch[1];
|
|
82
|
+
const base64Data = typeMatch?.[2] ?? "";
|
|
83
|
+
const byteCharacters = Buffer.from(base64Data, "base64").toString(
|
|
84
|
+
"binary"
|
|
85
|
+
);
|
|
86
|
+
const byteArrays = Array.of();
|
|
87
|
+
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
88
|
+
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
89
|
+
const byteNumbers = new Array(slice.length);
|
|
90
|
+
for (let i = 0; i < slice.length; i++) {
|
|
91
|
+
byteNumbers[i] = slice.charCodeAt(i);
|
|
92
|
+
}
|
|
93
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
94
|
+
byteArrays.push(byteArray);
|
|
95
|
+
}
|
|
96
|
+
const blob = new Blob(byteArrays, { type });
|
|
97
|
+
return blob;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
arrToArrOfArrs = /* @__PURE__ */ __name(({
|
|
101
|
+
arrToFragment = Array.of(),
|
|
102
|
+
arrOfArrsAggregator = Array.of(),
|
|
103
|
+
interval
|
|
104
|
+
}) => new Promise(
|
|
105
|
+
(resolve2, _reject) => resolve2(
|
|
106
|
+
((interval2) => {
|
|
107
|
+
for (let i = 0; i <= arrToFragment.length; i++) {
|
|
108
|
+
if ((i % interval2 === 0 || i === 0) && i <= arrToFragment.length) {
|
|
109
|
+
let segment = arrToFragment.slice(i, i + interval2);
|
|
110
|
+
arrOfArrsAggregator.push(segment);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})(interval)
|
|
114
|
+
)
|
|
115
|
+
).then((_) => arrOfArrsAggregator), "arrToArrOfArrs");
|
|
116
|
+
extractTuple(obj, props) {
|
|
117
|
+
return [props, obj[props]];
|
|
118
|
+
}
|
|
119
|
+
sort(obj, order) {
|
|
120
|
+
return Object.fromEntries(
|
|
121
|
+
Object.entries(obj).sort(
|
|
122
|
+
([a, _aa], [b, _bb]) => order === "DESC" ? b.localeCompare(a) - a.localeCompare(b) : a.localeCompare(b) - b.localeCompare(a)
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
excludeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
|
|
127
|
+
const resolve2 = Object.fromEntries(
|
|
128
|
+
Object.entries(obj).map(([key, val]) => {
|
|
129
|
+
if (props.includes(key)) {
|
|
130
|
+
return ["omit", "omit"];
|
|
131
|
+
} else return [key, val];
|
|
132
|
+
}).filter(([t, _v]) => /omit/.test(t) === false)
|
|
133
|
+
);
|
|
134
|
+
return typeof sort !== "undefined" ? this.sort(resolve2, sort) : resolve2;
|
|
135
|
+
}, "excludeTargeted");
|
|
136
|
+
includeTargeted = /* @__PURE__ */ __name((obj, props, sort) => {
|
|
137
|
+
const resolve2 = Object.fromEntries(
|
|
138
|
+
props.map((val) => this.extractTuple(obj, val))
|
|
139
|
+
);
|
|
140
|
+
return typeof sort !== "undefined" ? this.sort(resolve2, sort) : resolve2;
|
|
141
|
+
}, "includeTargeted");
|
|
142
|
+
countsSorter = /* @__PURE__ */ __name((counter, keySort = "ASC", valSort = "DESC") => Object.fromEntries(
|
|
143
|
+
Array.from(Object.entries(counter)).sort(
|
|
144
|
+
([aStr, _aNum], [bStr, _bNum]) => keySort === "DESC" ? bStr.localeCompare(aStr) - aStr.localeCompare(bStr) : aStr.localeCompare(bStr) - bStr.localeCompare(aStr)
|
|
145
|
+
).sort(([aStr, aNum], [bStr, bNum]) => {
|
|
146
|
+
if (typeof (aNum && bNum) === "number") {
|
|
147
|
+
return valSort === "ASC" ? aNum - bNum : bNum - aNum;
|
|
148
|
+
} else if (typeof (aNum && bNum) === "string") {
|
|
149
|
+
return valSort === "ASC" ? aStr.localeCompare(bStr) - bStr.localeCompare(aStr) : bStr.localeCompare(aStr) - aStr.localeCompare(bStr);
|
|
150
|
+
} else
|
|
151
|
+
throw new Error(
|
|
152
|
+
"only Record<string, string> and Record<string,number> types supported"
|
|
153
|
+
);
|
|
154
|
+
})
|
|
155
|
+
), "countsSorter");
|
|
156
|
+
range(from, to) {
|
|
157
|
+
const values = Array.of();
|
|
158
|
+
for (let i = from; i < to; i++) {
|
|
159
|
+
values.push(i);
|
|
160
|
+
}
|
|
161
|
+
return values;
|
|
162
|
+
}
|
|
163
|
+
isPrimeNumber = /* @__PURE__ */ __name((n) => {
|
|
164
|
+
for (let i = 2; n > i; i++) {
|
|
165
|
+
if (n % i === 0) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return n > 1;
|
|
170
|
+
}, "isPrimeNumber");
|
|
171
|
+
acceptor = /* @__PURE__ */ __name((num) => [...Array(num !== 0 ? num : this.range(num = -101, num = 101)).keys()].reverse().filter(this.isPrimeNumber), "acceptor");
|
|
172
|
+
};
|
|
173
|
+
|
|
46
174
|
// src/url/index.ts
|
|
47
|
-
var UrlService = class {
|
|
175
|
+
var UrlService = class extends UtilsService {
|
|
48
176
|
static {
|
|
49
177
|
__name(this, "UrlService");
|
|
50
178
|
}
|
|
@@ -1004,7 +1132,6 @@ var Fs = class extends MimeService {
|
|
|
1004
1132
|
writeTmp(filename, data, options) {
|
|
1005
1133
|
const fullPath = (0, import_path.resolve)(this.tmpDir, filename);
|
|
1006
1134
|
Promise.resolve(this.withWs(fullPath, data, options));
|
|
1007
|
-
return fullPath;
|
|
1008
1135
|
}
|
|
1009
1136
|
/**
|
|
1010
1137
|
* Read a file from the tmp directory
|
|
@@ -1048,9 +1175,11 @@ var Fs = class extends MimeService {
|
|
|
1048
1175
|
if (!pattern) {
|
|
1049
1176
|
return tmpContents;
|
|
1050
1177
|
}
|
|
1178
|
+
if (typeof pattern === "string") {
|
|
1179
|
+
return tmpContents.filter((t) => t.includes(pattern));
|
|
1180
|
+
}
|
|
1051
1181
|
return tmpContents.filter((path) => {
|
|
1052
|
-
|
|
1053
|
-
return filename.includes(pattern) || path.startsWith(pattern);
|
|
1182
|
+
return pattern.test(path);
|
|
1054
1183
|
});
|
|
1055
1184
|
}
|
|
1056
1185
|
/**
|
|
@@ -1136,6 +1265,10 @@ var Fs = class extends MimeService {
|
|
|
1136
1265
|
}
|
|
1137
1266
|
return removed;
|
|
1138
1267
|
}
|
|
1268
|
+
rmTmpFile(filename) {
|
|
1269
|
+
const tmpPath = (0, import_path.resolve)(this.tmpDir, filename);
|
|
1270
|
+
this.rmFile(tmpPath);
|
|
1271
|
+
}
|
|
1139
1272
|
/**
|
|
1140
1273
|
* Generate a unique tmp filename with optional prefix
|
|
1141
1274
|
* @param prefix Optional prefix for the filename
|
|
@@ -1154,5 +1287,56 @@ var Fs = class extends MimeService {
|
|
|
1154
1287
|
const parts = [prefix ?? "tmp", timestamp, random].join("-");
|
|
1155
1288
|
return extension ? `${parts}.${extension}` : parts;
|
|
1156
1289
|
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Async generator for cleaning tmp files with batched removal
|
|
1292
|
+
* @param pattern Pattern to match files for deletion
|
|
1293
|
+
* @param batchSize Number of files to remove per batch (default 10)
|
|
1294
|
+
* @yields Progress information during cleanup
|
|
1295
|
+
* @returns Final cleanup summary
|
|
1296
|
+
* @example
|
|
1297
|
+
* ```ts
|
|
1298
|
+
* const fs = new Fs(process.cwd());
|
|
1299
|
+
* // Clean up with progress tracking
|
|
1300
|
+
* for await (const progress of fs.cleanTmpGenerator("session-", 25)) {
|
|
1301
|
+
* console.log(progress);
|
|
1302
|
+
* }
|
|
1303
|
+
* ```
|
|
1304
|
+
*/
|
|
1305
|
+
async *cleanTmpGenerator(pattern, batchSize = 10) {
|
|
1306
|
+
const files = this.scanTmp(pattern);
|
|
1307
|
+
const batches = await this.arrToArrOfArrs({
|
|
1308
|
+
arrToFragment: files,
|
|
1309
|
+
arrOfArrsAggregator: [],
|
|
1310
|
+
interval: batchSize
|
|
1311
|
+
});
|
|
1312
|
+
let totalRemoved = 0;
|
|
1313
|
+
for (const [index, batch] of batches.entries()) {
|
|
1314
|
+
yield {
|
|
1315
|
+
action: "removing",
|
|
1316
|
+
batch: [...batch],
|
|
1317
|
+
batchNumber: index + 1,
|
|
1318
|
+
totalBatches: batches.length,
|
|
1319
|
+
totalFound: files.length,
|
|
1320
|
+
removed: totalRemoved
|
|
1321
|
+
};
|
|
1322
|
+
for (const file of batch) {
|
|
1323
|
+
this.rmTmpFile(file);
|
|
1324
|
+
totalRemoved++;
|
|
1325
|
+
}
|
|
1326
|
+
yield {
|
|
1327
|
+
action: "batch-complete",
|
|
1328
|
+
batchNumber: index + 1,
|
|
1329
|
+
batchSize: batch.length,
|
|
1330
|
+
totalRemoved,
|
|
1331
|
+
remaining: files.length - totalRemoved
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
return {
|
|
1335
|
+
action: "complete",
|
|
1336
|
+
totalRemoved,
|
|
1337
|
+
totalBatches: batches.length,
|
|
1338
|
+
pattern: pattern.toString()
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1157
1341
|
};
|
|
1158
1342
|
//# sourceMappingURL=index.cjs.map
|
package/dist/fs/index.d.cts
CHANGED
|
@@ -2,9 +2,10 @@ import expand from 'dotenv-expand';
|
|
|
2
2
|
import sharp from 'sharp';
|
|
3
3
|
import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, Unit, SizeOpts, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.cjs';
|
|
4
4
|
import { MimeService } from '../mime/index.cjs';
|
|
5
|
+
import '../url/index.cjs';
|
|
6
|
+
import '../utils/index.cjs';
|
|
5
7
|
import 'stream';
|
|
6
8
|
import 'buffer';
|
|
7
|
-
import '../url/index.cjs';
|
|
8
9
|
|
|
9
10
|
declare class Fs extends MimeService {
|
|
10
11
|
cwd: string;
|
|
@@ -112,12 +113,12 @@ declare class Fs extends MimeService {
|
|
|
112
113
|
fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
|
|
113
114
|
dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
|
|
114
115
|
assetToBuffer<const T extends string>(path: T): Promise<{
|
|
115
|
-
readonly b64encodedData: `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/aces;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;base64, ${string}` | `data:image/avci;base64, ${string}` | `data:image/avif;base64, ${string}` | `data:video/x-msvideo;base64, ${string}` | `data:application/vnd.amazon.ebook;base64, ${string}` | `data:
|
|
116
|
-
readonly extension: "
|
|
116
|
+
readonly b64encodedData: `data:application/octet-stream;base64, ${string}` | `data:audio/aac;base64, ${string}` | `data:application/x-abiword;base64, ${string}` | `data:image/aces;base64, ${string}` | `data:image/apng;base64, ${string}` | `data:application/x-freearc;base64, ${string}` | `data:image/avci;base64, ${string}` | `data:image/avif;base64, ${string}` | `data:video/x-msvideo;base64, ${string}` | `data:application/vnd.amazon.ebook;base64, ${string}` | `data:multipart/voice-message;base64, ${string}` | `data:image/bmp;base64, ${string}` | `data:application/x-bzip;base64, ${string}` | `data:application/x-bzip2;base64, ${string}` | `data:application/x-cdf;base64, ${string}` | `data:application/node;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/x-csh;base64, ${string}` | `data:text/css;base64, ${string}` | `data:text/csv;base64, ${string}` | `data:application/msword;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64, ${string}` | `data:image/dpx;base64, ${string}` | `data:image/emf;base64, ${string}` | `data:application/vnd.ms-fontobject;base64, ${string}` | `data:application/epub+zip;base64, ${string}` | `data:image/gif;base64, ${string}` | `data:model/gltf-binary;base64, ${string}` | `data:model/gltf+json;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:haptics/hjif;base64, ${string}` | `data:haptics/hmpg;base64, ${string}` | `data:text/html;base64, ${string}` | `data:image/vnd.microsoft.icon;base64, ${string}` | `data:text/calendar;base64, ${string}` | `data:haptics/ivs;base64, ${string}` | `data:application/java-archive;base64, ${string}` | `data:image/jpeg;base64, ${string}` | `data:application/json;base64, ${string}` | `data:application/ld+json;base64, ${string}` | `data:image/ktx;base64, ${string}` | `data:image/ktx2;base64, ${string}` | `data:application/vnd.apple.mpegurl;base64, ${string}` | `data:audio/mp4;base64, ${string}` | `data:video/mp4;base64, ${string}` | `data:text/markdown;base64, ${string}` | `data:application/x-mdx;base64, ${string}` | `data:audio/midi;base64, ${string}` | `data:audio/x-midi;base64, ${string}` | `data:audio/mpeg;base64, ${string}` | `data:video/mpeg;base64, ${string}` | `data:application/vnd.apple.installer+xml;base64, ${string}` | `data:application/x-ndjson;base64, ${string}` | `data:model/obj;base64, ${string}` | `data:text/plain;base64, ${string}` | `data:application/vnd.oasis.opendocument.presentation;base64, ${string}` | `data:application/vnd.oasis.opendocument.spreadsheet;base64, ${string}` | `data:application/vnd.oasis.opendocument.text;base64, ${string}` | `data:audio/ogg;base64, ${string}` | `data:video/ogg;base64, ${string}` | `data:application/ogg;base64, ${string}` | `data:font/otf;base64, ${string}` | `data:image/png;base64, ${string}` | `data:application/pdf;base64, ${string}` | `data:application/x-httpd-php;base64, ${string}` | `data:application/vnd.apple.pkpass;base64, ${string}` | `data:application/vnd.ms-powerpoint;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64, ${string}` | `data:text/x-python;base64, ${string}` | `data:application/x-python-code;base64, ${string}` | `data:application/vnd.rar;base64, ${string}` | `data:text/rust;base64, ${string}` | `data:application/rtf;base64, ${string}` | `data:application/x-sh;base64, ${string}` | `data:application/sql;base64, ${string}` | `data:text/event-stream;base64, ${string}` | `data:image/svg+xml;base64, ${string}` | `data:application/x-tar;base64, ${string}` | `data:image/tiff;base64, ${string}` | `data:application/toml;base64, ${string}` | `data:text/typescript;base64, ${string}` | `data:video/mp2t;base64, ${string}` | `data:video/vnd.dlna.mpeg-tts;base64, ${string}` | `data:application/font-sfnt;base64, ${string}` | `data:font/ttf;base64, ${string}` | `data:model/vnd.usdz+zip;base64, ${string}` | `data:application/vnd.visio;base64, ${string}` | `data:text/vtt;base64, ${string}` | `data:application/wasm;base64, ${string}` | `data:audio/wav;base64, ${string}` | `data:video/webm;base64, ${string}` | `data:image/webp;base64, ${string}` | `data:font/woff;base64, ${string}` | `data:font/woff2;base64, ${string}` | `data:application/xhtml+xml;base64, ${string}` | `data:application/vnd.ms-excel;base64, ${string}` | `data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64, ${string}` | `data:application/xml;base64, ${string}` | `data:application/vnd.mozilla.xul+xml;base64, ${string}` | `data:application/yaml;base64, ${string}` | `data:application/zip;base64, ${string}` | `data:application/x-zip-compressed;base64, ${string}` | `data:video/3gpp;base64, ${string}` | `data:video/3gpp2;base64, ${string}` | `data:application/x-7z-compressed;base64, ${string}`;
|
|
117
|
+
readonly extension: "aac" | "abw" | "aces" | "apng" | "arc" | "avci" | "avif" | "avi" | "azw" | "bin" | "bmp" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "doc" | "docx" | "dpx" | "emf" | "eot" | "epub" | "gif" | "glb" | "gltf" | "gz" | "hjif" | "hmpg" | "htm" | "html" | "ico" | "ics" | "ivs" | "ivt" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "node" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rs" | "rtf" | "sh" | "sql" | "sse" | "svg" | "tar" | "tif" | "tiff" | "toml" | "ts" | "ttf" | "txt" | "usdz" | "vsd" | "vtt" | "wasm" | "wav" | "weba" | "webp" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "yaml" | "yml" | "zip" | "3gp" | "3g2" | "7z";
|
|
117
118
|
}>;
|
|
118
119
|
assetToBufferView<const T extends string>(path: T): Promise<{
|
|
119
120
|
readonly b64encodedData: string;
|
|
120
|
-
readonly extension: "
|
|
121
|
+
readonly extension: "aac" | "abw" | "aces" | "apng" | "arc" | "avci" | "avif" | "avi" | "azw" | "bin" | "bmp" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "doc" | "docx" | "dpx" | "emf" | "eot" | "epub" | "gif" | "glb" | "gltf" | "gz" | "hjif" | "hmpg" | "htm" | "html" | "ico" | "ics" | "ivs" | "ivt" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "node" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rs" | "rtf" | "sh" | "sql" | "sse" | "svg" | "tar" | "tif" | "tiff" | "toml" | "ts" | "ttf" | "txt" | "usdz" | "vsd" | "vtt" | "wasm" | "wav" | "weba" | "webp" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "yaml" | "yml" | "zip" | "3gp" | "3g2" | "7z" | undefined;
|
|
121
122
|
}>;
|
|
122
123
|
formatHelper<const T extends string>(f: T): string;
|
|
123
124
|
cleanDataUrl<const C extends string>(props: C): string;
|
|
@@ -213,7 +214,7 @@ declare class Fs extends MimeService {
|
|
|
213
214
|
* fs.writeTmp("img-probe/output.png", imageBuffer);
|
|
214
215
|
* ```
|
|
215
216
|
*/
|
|
216
|
-
writeTmp<const F extends string>(filename: F, data: WriteStreamDataShape, options?: WriteStreamOptions):
|
|
217
|
+
writeTmp<const F extends string>(filename: F, data: WriteStreamDataShape, options?: WriteStreamOptions): void;
|
|
217
218
|
/**
|
|
218
219
|
* Read a file from the tmp directory
|
|
219
220
|
* @param filename The filename to read (can include subdirectories)
|
|
@@ -240,7 +241,7 @@ declare class Fs extends MimeService {
|
|
|
240
241
|
* const allFiles = fs.scanTmp();
|
|
241
242
|
* ```
|
|
242
243
|
*/
|
|
243
|
-
scanTmp(pattern?: string, options?: ReadDirOptions): string[];
|
|
244
|
+
scanTmp(pattern?: string | RegExp, options?: ReadDirOptions): string[];
|
|
244
245
|
/**
|
|
245
246
|
* Extract specific files from tmp directory to a target location
|
|
246
247
|
* @param pattern Pattern to match files (e.g., "img-probe")
|
|
@@ -279,6 +280,7 @@ declare class Fs extends MimeService {
|
|
|
279
280
|
* ```
|
|
280
281
|
*/
|
|
281
282
|
cleanupTmp(pattern: string, maxAge?: number): number;
|
|
283
|
+
rmTmpFile<const V extends string>(filename: V): void;
|
|
282
284
|
/**
|
|
283
285
|
* Generate a unique tmp filename with optional prefix
|
|
284
286
|
* @param prefix Optional prefix for the filename
|
|
@@ -292,6 +294,47 @@ declare class Fs extends MimeService {
|
|
|
292
294
|
* ```
|
|
293
295
|
*/
|
|
294
296
|
uniqueTmpName(prefix?: string, extension?: string): string;
|
|
297
|
+
/**
|
|
298
|
+
* Async generator for cleaning tmp files with batched removal
|
|
299
|
+
* @param pattern Pattern to match files for deletion
|
|
300
|
+
* @param batchSize Number of files to remove per batch (default 10)
|
|
301
|
+
* @yields Progress information during cleanup
|
|
302
|
+
* @returns Final cleanup summary
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* const fs = new Fs(process.cwd());
|
|
306
|
+
* // Clean up with progress tracking
|
|
307
|
+
* for await (const progress of fs.cleanTmpGenerator("session-", 25)) {
|
|
308
|
+
* console.log(progress);
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
cleanTmpGenerator(pattern: string | RegExp, batchSize?: number): AsyncGenerator<{
|
|
313
|
+
action: "removing";
|
|
314
|
+
batch: string[];
|
|
315
|
+
batchNumber: number;
|
|
316
|
+
totalBatches: number;
|
|
317
|
+
totalFound: number;
|
|
318
|
+
removed: number;
|
|
319
|
+
batchSize?: undefined;
|
|
320
|
+
totalRemoved?: undefined;
|
|
321
|
+
remaining?: undefined;
|
|
322
|
+
} | {
|
|
323
|
+
action: "batch-complete";
|
|
324
|
+
batchNumber: number;
|
|
325
|
+
batchSize: number;
|
|
326
|
+
totalRemoved: number;
|
|
327
|
+
remaining: number;
|
|
328
|
+
batch?: undefined;
|
|
329
|
+
totalBatches?: undefined;
|
|
330
|
+
totalFound?: undefined;
|
|
331
|
+
removed?: undefined;
|
|
332
|
+
}, {
|
|
333
|
+
action: "complete";
|
|
334
|
+
totalRemoved: number;
|
|
335
|
+
totalBatches: number;
|
|
336
|
+
pattern: string;
|
|
337
|
+
}, unknown>;
|
|
295
338
|
}
|
|
296
339
|
|
|
297
340
|
export = Fs;
|