@d0paminedriven/fs 7.1.0 → 7.2.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.
@@ -1,464 +0,0 @@
1
- import expand from 'dotenv-expand';
2
- import sharp from 'sharp';
3
- import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, Unit, SizeOpts, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.cjs';
4
- import { ImageService } from '../image/index.cjs';
5
- import '../mime/index.cjs';
6
- import '../url/index.cjs';
7
- import '../utils/index.cjs';
8
- import 'stream';
9
- import 'buffer';
10
-
11
- declare class Fs extends ImageService {
12
- cwd: string;
13
- constructor(cwd: string);
14
- getImageSpecs(filePath: string): Promise<{
15
- width: number;
16
- height: number;
17
- format: "png";
18
- frames: number;
19
- animated: boolean;
20
- hasAlpha: boolean;
21
- orientation: null;
22
- aspectRatio: number;
23
- colorSpace: "unknown" | "rgb" | "rgba" | "grayscale" | "grayscale-alpha" | "indexed";
24
- iccProfile: string | null;
25
- exifDateTimeOriginal: string | null;
26
- } | {
27
- width: number;
28
- height: number;
29
- format: "jpeg";
30
- frames: number;
31
- animated: false;
32
- hasAlpha: false;
33
- orientation: number | null;
34
- aspectRatio: number;
35
- colorSpace: "unknown" | "grayscale" | "ycbcr" | "ycck";
36
- iccProfile: string | null;
37
- exifDateTimeOriginal: string | null;
38
- } | {
39
- width: number;
40
- height: number;
41
- format: "gif";
42
- frames: number;
43
- animated: boolean;
44
- hasAlpha: null;
45
- orientation: null;
46
- aspectRatio: number;
47
- colorSpace: "indexed";
48
- iccProfile: null;
49
- exifDateTimeOriginal: null;
50
- } | {
51
- width: number;
52
- height: number;
53
- format: "bmp";
54
- frames: number;
55
- animated: false;
56
- hasAlpha: null;
57
- orientation: number;
58
- aspectRatio: number;
59
- colorSpace: "rgb" | "indexed";
60
- iccProfile: null;
61
- exifDateTimeOriginal: null;
62
- } | {
63
- width: number;
64
- height: number;
65
- format: "webp";
66
- frames: number;
67
- animated: boolean;
68
- hasAlpha: boolean;
69
- orientation: null;
70
- aspectRatio: number;
71
- colorSpace: "unknown" | "rgb" | "rgba";
72
- iccProfile: string | null;
73
- exifDateTimeOriginal: null;
74
- } | {
75
- width: number;
76
- height: number;
77
- format: "avif";
78
- frames: number;
79
- animated: boolean;
80
- hasAlpha: true | null;
81
- orientation: null;
82
- aspectRatio: number;
83
- colorSpace: "unknown" | "rgb" | "rgba" | "grayscale" | "grayscale-alpha" | "indexed" | "cmyk" | "ycbcr" | "ycck";
84
- iccProfile: string | null;
85
- exifDateTimeOriginal: string | null;
86
- }>;
87
- getImageSpecsTmp(target: string): Promise<{
88
- width: number;
89
- height: number;
90
- format: "png";
91
- frames: number;
92
- animated: boolean;
93
- hasAlpha: boolean;
94
- orientation: null;
95
- aspectRatio: number;
96
- colorSpace: "unknown" | "rgb" | "rgba" | "grayscale" | "grayscale-alpha" | "indexed";
97
- iccProfile: string | null;
98
- exifDateTimeOriginal: string | null;
99
- } | {
100
- width: number;
101
- height: number;
102
- format: "jpeg";
103
- frames: number;
104
- animated: false;
105
- hasAlpha: false;
106
- orientation: number | null;
107
- aspectRatio: number;
108
- colorSpace: "unknown" | "grayscale" | "ycbcr" | "ycck";
109
- iccProfile: string | null;
110
- exifDateTimeOriginal: string | null;
111
- } | {
112
- width: number;
113
- height: number;
114
- format: "gif";
115
- frames: number;
116
- animated: boolean;
117
- hasAlpha: null;
118
- orientation: null;
119
- aspectRatio: number;
120
- colorSpace: "indexed";
121
- iccProfile: null;
122
- exifDateTimeOriginal: null;
123
- } | {
124
- width: number;
125
- height: number;
126
- format: "bmp";
127
- frames: number;
128
- animated: false;
129
- hasAlpha: null;
130
- orientation: number;
131
- aspectRatio: number;
132
- colorSpace: "rgb" | "indexed";
133
- iccProfile: null;
134
- exifDateTimeOriginal: null;
135
- } | {
136
- width: number;
137
- height: number;
138
- format: "webp";
139
- frames: number;
140
- animated: boolean;
141
- hasAlpha: boolean;
142
- orientation: null;
143
- aspectRatio: number;
144
- colorSpace: "unknown" | "rgb" | "rgba";
145
- iccProfile: string | null;
146
- exifDateTimeOriginal: null;
147
- } | {
148
- width: number;
149
- height: number;
150
- format: "avif";
151
- frames: number;
152
- animated: boolean;
153
- hasAlpha: true | null;
154
- orientation: null;
155
- aspectRatio: number;
156
- colorSpace: "unknown" | "rgb" | "rgba" | "grayscale" | "grayscale-alpha" | "indexed" | "cmyk" | "ycbcr" | "ycck";
157
- iccProfile: string | null;
158
- exifDateTimeOriginal: string | null;
159
- }>;
160
- private get myEnv();
161
- get tmpDir(): string;
162
- get tmpDirRelative(): string;
163
- parseDotEnv(): expand.DotenvExpandOutput;
164
- /**
165
- *
166
- * @param target path to the file or directory to check for existence
167
- * @returns true if the file or directory exists, false otherwise
168
- * @example
169
- * ```ts
170
- * const fs = new Fs(process.cwd());
171
- * const exists = fs.exists("my-file.txt");
172
- * console.log(exists); // true if the file exists, false otherwise
173
- * ```
174
- * @description
175
- * This method checks if a file or directory exists at the specified path input
176
- *
177
- * Additional Note:
178
- *
179
- * say you have a directory that begins with a dot, such as `.turbo`;
180
- *
181
- * in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
182
- *
183
- */
184
- exists<const T extends string>(target: T): boolean;
185
- /**
186
- *
187
- * @param ms milliseconds to wait
188
- * @returns a promise that resolves after the specified number of milliseconds
189
- * @example
190
- * ```ts
191
- * const fs = new Fs(process.cwd());
192
- * await fs.wait(1000); // waits for 1 second
193
- * console.log("Done waiting!");
194
- * ```
195
- *
196
- * Alternatively, you can use it like this:
197
- * ```ts
198
- * const fs = new Fs(process.cwd());
199
- * fs.wait(1000).then(() => { // waits for 1 second
200
- * console.log("Done waiting!");
201
- * // do something after waiting
202
- * });
203
- * ```
204
- *
205
- * @description
206
- * This method is useful for delaying execution in asynchronous code, such as when you need to wait for a file operation to complete or when you want to introduce a delay in a loop.
207
- */
208
- wait<T extends number>(ms: T): Promise<unknown>;
209
- /**
210
- * Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
211
- * @param arr An array or readonly array of strings and/or Buffers
212
- * @returns An array of strings with Buffers converted to UTF-8 strings.
213
- */
214
- handleBuffStrArrUnion<const T extends (string | Buffer)[] | readonly (string | Buffer)[]>(arr: T): string[];
215
- isRootPathTargeted<const T extends string>(path: T): boolean;
216
- /**
217
- *
218
- * @param path path to the directory relative to the cwd
219
- * @param options options for reading the directory, defaults to recursive
220
- *
221
- * The following two examples are equivalent:
222
- *
223
- * @example
224
- * ```ts
225
- * const fs = new Fs(process.cwd());
226
- * const files = fs.readDir("./my-directory", { recursive: true });
227
- * console.log(files);
228
- * ```
229
- * @example
230
- * ```ts
231
- * const fs = new Fs(process.cwd());
232
- * const files = fs.readDir("my-directory", { recursive: true });
233
- * console.log(files);
234
- * ```
235
- *
236
- * @returns an array of strings representing the contents of the directory
237
- */
238
- readDir<const T extends string>(path: T, options?: ReadDirOptions): string[];
239
- executeCommand: <const T extends string>({ command, ...options }: ExecuteCommandProps<T>) => string;
240
- existsSync<const T extends string>(path: T): boolean;
241
- pathHandler<const T extends string>(path: T): string;
242
- mkdirSync<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
243
- private units;
244
- private u;
245
- autoFileSizeRaw(size: number | bigint): {
246
- value: number;
247
- unit: "B" | "KB" | "MB" | "GB" | "TB" | "PB" | undefined;
248
- };
249
- getSize<const S extends Unit | Lowercase<Unit> | "auto">(size: number | bigint, target: S, opts?: SizeOpts): string | number;
250
- fileSizeMb<const T extends string>(path: T): number;
251
- fileSize<const T extends string, const S extends Unit | Lowercase<Unit> | "auto">(path: T, target: S, opts?: SizeOpts): string | number;
252
- generateDirIfDNE<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
253
- withWs<const T extends string>(path: T, data: WriteStreamDataShape, options?: WriteStreamOptions): string | boolean | undefined;
254
- writeFileAsync: <const T extends string>(path: T, data: WriteFileAsyncDataUnion, options?: WriteFileAsyncOptions) => Promise<string | void>;
255
- unlink<const P extends string>(path: P): Promise<void>;
256
- rmFile<const FP extends string>(filePath: FP): void;
257
- rmdir<const D extends string>(dir: D, options?: RmDirOptions): Promise<void>;
258
- rmDirSync<const D extends string>(dir: D): void;
259
- fileToBuffer: <const T extends string>(path: T) => Buffer<ArrayBuffer>;
260
- fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
261
- dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
262
- assetToBuffer<const T extends string>(path: T): Promise<{
263
- 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:application/octet-stream;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:image/x-icon;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:application/dash+xml;base64, ${string}` | `data:video/mpeg;base64, ${string}` | `data:application/vnd.apple.installer+xml;base64, ${string}` | `data:application/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:audio/webm;base64, ${string}` | `data:video/webm;base64, ${string}` | `data:application/manifest+json;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:text/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}`;
264
- readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "mpd" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonld" | "webmanifest" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "toml" | "azw" | "mpkg" | "m3u8" | "pkpass" | "xul" | "xls" | "eot" | "ppt" | "odp" | "ods" | "odt" | "pptx" | "xlsx" | "docx" | "rar" | "vsd" | "wasm" | "7z" | "abw" | "bz" | "bz2" | "cda" | "csh" | "arc" | "php" | "mdx" | "ndjson" | "pyc" | "sh" | "tar" | "zip" | "xhtml" | "xml" | "mtlx" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "weba" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "dpx" | "emf" | "jpg" | "jpe" | "jif" | "jfif" | "pjp" | "pjpeg" | "ktx" | "ktx2" | "svg" | "tiff" | "tif" | "ico" | "cur" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "html" | "htm" | "mjs" | "cjs" | "md" | "txt" | "rs" | "ts" | "vtt" | "py" | "3gp" | "3g2" | "mp4" | "m4v" | "mpeg" | "ogv" | "webm" | "avi";
265
- }>;
266
- assetToBufferView<const T extends string>(path: T): Promise<{
267
- readonly b64encodedData: string;
268
- readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "mpd" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonld" | "webmanifest" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "toml" | "azw" | "mpkg" | "m3u8" | "pkpass" | "xul" | "xls" | "eot" | "ppt" | "odp" | "ods" | "odt" | "pptx" | "xlsx" | "docx" | "rar" | "vsd" | "wasm" | "7z" | "abw" | "bz" | "bz2" | "cda" | "csh" | "arc" | "php" | "mdx" | "ndjson" | "pyc" | "sh" | "tar" | "zip" | "xhtml" | "xml" | "mtlx" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "weba" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "dpx" | "emf" | "jpg" | "jpe" | "jif" | "jfif" | "pjp" | "pjpeg" | "ktx" | "ktx2" | "svg" | "tiff" | "tif" | "ico" | "cur" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "html" | "htm" | "mjs" | "cjs" | "md" | "txt" | "rs" | "ts" | "vtt" | "py" | "3gp" | "3g2" | "mp4" | "m4v" | "mpeg" | "ogv" | "webm" | "avi" | undefined;
269
- }>;
270
- formatHelper<const T extends string>(f: T): string;
271
- cleanDataUrl<const C extends string>(props: C): string;
272
- /**
273
- *
274
- * @param inputUrl remote url to fetch data from
275
- * @param outputPath desired output path relative to the cwd
276
- * @param useDetectedExtension optional, defaults to true
277
- *
278
- * if `useDetectedExtension` is false you must include the file extension in your output path &rarr;
279
- *
280
- * 🚫 'public/assets/image-1'
281
- *
282
- * ✅ 'public/assets/image-1.png'
283
- */
284
- fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
285
- private knownToBlockHead;
286
- /**
287
- *
288
- * @param inputUrl remote url to fetch data from
289
- * @param outputPath desired output path relative to the cwd
290
- * @param useDetectedExtension optional, defaults to true
291
- *
292
- * if `useDetectedExtension` is false you must include the file extension in your output path &rarr;
293
- *
294
- * 🚫 'public/assets/image-1'
295
- *
296
- * ✅ 'public/assets/image-1.png'
297
- *
298
- * @description
299
- * This method is designed for all files regardless of size, but especially for
300
- * larger files that may not fit into memory (it intelligently determines the best approach on the fly)
301
- * For files > 100 MB, it streams the data directly to disk instead of loading it all into memory
302
- */
303
- fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPathI: O, useDetectedExtension?: boolean): Promise<void>;
304
- /**
305
- *
306
- * @access package-private
307
- *
308
- * work in progress, for internal package maintainer use only
309
- */
310
- imageTransform<const F extends "webp" | "avif" | "jpg" | "png" | "tif" | "tiff" | "jp2" | "jpeg">({ format, target, quality, tint, resize }: {
311
- format: F;
312
- target: Buffer<ArrayBuffer>;
313
- quality?: number;
314
- tint?: string | {
315
- r?: number | undefined;
316
- g?: number | undefined;
317
- b?: number | undefined;
318
- alpha?: number | undefined;
319
- };
320
- resize?: {
321
- widthOrOptions?: number | sharp.ResizeOptions | null;
322
- height?: number | null;
323
- options?: sharp.ResizeOptions;
324
- };
325
- }): Promise<Buffer<ArrayBufferLike>>;
326
- /**
327
- * Write data to a file in the system's tmp directory
328
- * @param filename The filename (can include subdirectories like "img-probe/file.txt")
329
- * @param data The data to write
330
- * @param options Optional write stream options
331
- * @returns The full path to the written file
332
- * @example
333
- * ```ts
334
- * const fs = new Fs(process.cwd());
335
- * const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
336
- * // Or with a subdirectory:
337
- * fs.writeTmp("img-probe/output.png", imageBuffer);
338
- * ```
339
- */
340
- writeTmp<const F extends string>(filename: F, data: WriteStreamDataShape, options?: WriteStreamOptions): void;
341
- readTmpAsync<const F extends string>(filename: F): Promise<Buffer<ArrayBufferLike>>;
342
- /**
343
- * Read a file from the tmp directory
344
- * @param filename The filename to read (can include subdirectories)
345
- * @returns Buffer containing the file data
346
- * @example
347
- * ```ts
348
- * const fs = new Fs(process.cwd());
349
- * const data = fs.readTmp("session-data.json");
350
- * const parsed = JSON.parse(data.toString("utf-8"));
351
- * ```
352
- */
353
- readTmp<const F extends string>(filename: F): Buffer<ArrayBuffer>;
354
- /**
355
- * Scan the tmp directory for files matching a pattern
356
- * @param pattern Optional pattern to filter files (e.g., "img-probe")
357
- * @param options Options for directory reading (defaults to non-recursive to avoid permission issues)
358
- * @returns Array of matching file paths relative to tmp directory
359
- * @example
360
- * ```ts
361
- * const fs = new Fs(process.cwd());
362
- * // Get all img-probe files
363
- * const imgFiles = fs.scanTmp("img-probe");
364
- * // Get all files in tmp (non-recursive)
365
- * const allFiles = fs.scanTmp();
366
- * ```
367
- */
368
- scanTmp(pattern?: string | RegExp, options?: ReadDirOptions): string[];
369
- /**
370
- * Extract specific files from tmp directory to a target location
371
- * @param pattern Pattern to match files (e.g., "img-probe")
372
- * @param targetDir Target directory to extract files to
373
- * @param options Options for extraction behavior
374
- * @returns Array of extracted file paths
375
- * @example
376
- * ```ts
377
- * const fs = new Fs(process.cwd());
378
- * // Extract all img-probe files to ./output
379
- * const extracted = fs.extractFromTmp("img-probe", "./output");
380
- * // Extract with custom behavior
381
- * fs.extractFromTmp("session-", "./sessions", {
382
- * preserveStructure: true,
383
- * cleanupAfter: true
384
- * });
385
- * ```
386
- */
387
- extractFromTmp(pattern: string, targetDir: string, options?: {
388
- preserveStructure?: boolean;
389
- cleanupAfter?: boolean;
390
- overwrite?: boolean;
391
- }): string[];
392
- /**
393
- * Clean up tmp files matching a pattern
394
- * @param pattern Pattern to match files for deletion
395
- * @param maxAge Optional max age in milliseconds (only delete files older than this)
396
- * @returns Number of files removed
397
- * @example
398
- * ```ts
399
- * const fs = new Fs(process.cwd());
400
- * // Remove all img-probe files
401
- * fs.cleanupTmp("img-probe");
402
- * // Remove session files older than 1 hour
403
- * fs.cleanupTmp("session-", 60 * 60 * 1000);
404
- * ```
405
- */
406
- cleanupTmp(pattern: string, maxAge?: number): number;
407
- rmTmpFile<const V extends string>(filename: V): void;
408
- /**
409
- * Generate a unique tmp filename with optional prefix
410
- * @param prefix Optional prefix for the filename
411
- * @param extension Optional file extension (without dot)
412
- * @returns Unique filename
413
- * @example
414
- * ```ts
415
- * const fs = new Fs(process.cwd());
416
- * const filename = fs.uniqueTmpName("img-probe", "png");
417
- * // Returns: "img-probe-1701234567890-a3b2c1.png"
418
- * ```
419
- */
420
- uniqueTmpName(prefix?: string, extension?: string): string;
421
- /**
422
- * Async generator for cleaning tmp files with batched removal
423
- * @param pattern Pattern to match files for deletion
424
- * @param batchSize Number of files to remove per batch (default 10)
425
- * @yields Progress information during cleanup
426
- * @returns Final cleanup summary
427
- * @example
428
- * ```ts
429
- * const fs = new Fs(process.cwd());
430
- * // Clean up with progress tracking
431
- * for await (const progress of fs.cleanTmpGenerator("session-", 25)) {
432
- * console.log(progress);
433
- * }
434
- * ```
435
- */
436
- cleanTmpGenerator(pattern: string | RegExp, batchSize?: number): AsyncGenerator<{
437
- action: "removing";
438
- batch: string[];
439
- batchNumber: number;
440
- totalBatches: number;
441
- totalFound: number;
442
- removed: number;
443
- batchSize?: undefined;
444
- totalRemoved?: undefined;
445
- remaining?: undefined;
446
- } | {
447
- action: "batch-complete";
448
- batchNumber: number;
449
- batchSize: number;
450
- totalRemoved: number;
451
- remaining: number;
452
- batch?: undefined;
453
- totalBatches?: undefined;
454
- totalFound?: undefined;
455
- removed?: undefined;
456
- }, {
457
- action: "complete";
458
- totalRemoved: number;
459
- totalBatches: number;
460
- pattern: string;
461
- }, unknown>;
462
- }
463
-
464
- export = Fs;