@d0paminedriven/fs 6.1.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 +389 -64
- package/dist/{chunk-QMN5ZCE4.js → chunk-IUGBPDQJ.js} +21 -16
- package/dist/{chunk-4X5DVWVM.js → chunk-MXEE2WS7.js} +1 -1
- package/dist/chunk-O4BKLMFV.js +307 -0
- package/dist/{chunk-XHN56MDK.js → chunk-QBG7TFHM.js} +5 -2
- package/dist/{chunk-XIAKCF2X.js → chunk-Y3TLKN7F.js} +414 -8
- package/dist/fs/index.cjs +688 -9
- package/dist/fs/index.d.cts +186 -5
- package/dist/fs/index.d.ts +186 -5
- package/dist/fs/index.js +5 -4
- package/dist/index.cjs +676 -118
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -6
- package/dist/mime/index.cjs +281 -6
- package/dist/mime/index.d.cts +244 -11
- package/dist/mime/index.d.ts +244 -11
- package/dist/mime/index.js +7 -4
- package/dist/types/index.d.cts +93 -31
- package/dist/types/index.d.ts +93 -31
- package/dist/types/index.js +1 -1
- 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/dist/utils/index.cjs +20 -15
- package/dist/utils/index.d.cts +2 -6
- package/dist/utils/index.d.ts +2 -6
- package/dist/utils/index.js +1 -1
- package/package.json +13 -13
- package/dist/chunk-EHOBCDHE.js +0 -161
package/dist/fs/index.d.cts
CHANGED
|
@@ -2,14 +2,17 @@ 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;
|
|
11
12
|
constructor(cwd: string);
|
|
12
13
|
private get myEnv();
|
|
14
|
+
get tmpDir(): string;
|
|
15
|
+
get tmpDirRelative(): string;
|
|
13
16
|
parseDotEnv(): expand.DotenvExpandOutput;
|
|
14
17
|
/**
|
|
15
18
|
*
|
|
@@ -107,14 +110,15 @@ declare class Fs extends MimeService {
|
|
|
107
110
|
rmdir<const D extends string>(dir: D, options?: RmDirOptions): Promise<void>;
|
|
108
111
|
rmDirSync<const D extends string>(dir: D): void;
|
|
109
112
|
fileToBuffer: <const T extends string>(path: T) => Buffer<ArrayBuffer>;
|
|
113
|
+
fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
|
|
110
114
|
dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
|
|
111
115
|
assetToBuffer<const T extends string>(path: T): Promise<{
|
|
112
|
-
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: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/
|
|
113
|
-
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" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rtf" | "sh" | "sql" | "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";
|
|
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";
|
|
114
118
|
}>;
|
|
115
119
|
assetToBufferView<const T extends string>(path: T): Promise<{
|
|
116
120
|
readonly b64encodedData: 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" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rtf" | "sh" | "sql" | "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
|
+
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;
|
|
118
122
|
}>;
|
|
119
123
|
formatHelper<const T extends string>(f: T): string;
|
|
120
124
|
cleanDataUrl<const C extends string>(props: C): string;
|
|
@@ -131,7 +135,49 @@ declare class Fs extends MimeService {
|
|
|
131
135
|
* ✅ 'public/assets/image-1.png'
|
|
132
136
|
*/
|
|
133
137
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
134
|
-
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param inputUrl remote url to fetch data from
|
|
141
|
+
* @param outputPath desired output path relative to the cwd
|
|
142
|
+
* @param useDetectedExtension optional, defaults to true
|
|
143
|
+
*
|
|
144
|
+
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
145
|
+
*
|
|
146
|
+
* 🚫 'public/assets/image-1'
|
|
147
|
+
*
|
|
148
|
+
* ✅ 'public/assets/image-1.png'
|
|
149
|
+
*
|
|
150
|
+
* @description
|
|
151
|
+
* This method is designed for large files that may not fit into memory.
|
|
152
|
+
* It streams the data directly to disk instead of loading it all into memory.
|
|
153
|
+
*/
|
|
154
|
+
fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPathI: O, useDetectedExtension?: boolean): Promise<void>;
|
|
155
|
+
private findBox;
|
|
156
|
+
getImageSize(filePath: string): Promise<{
|
|
157
|
+
width: number;
|
|
158
|
+
height: number;
|
|
159
|
+
type: "png";
|
|
160
|
+
} | {
|
|
161
|
+
width: number;
|
|
162
|
+
height: number;
|
|
163
|
+
type: "jpeg";
|
|
164
|
+
} | {
|
|
165
|
+
width: number;
|
|
166
|
+
height: number;
|
|
167
|
+
type: "gif";
|
|
168
|
+
} | {
|
|
169
|
+
width: number;
|
|
170
|
+
height: number;
|
|
171
|
+
type: "bmp";
|
|
172
|
+
} | {
|
|
173
|
+
width: number;
|
|
174
|
+
height: number;
|
|
175
|
+
type: "webp";
|
|
176
|
+
} | {
|
|
177
|
+
width: number;
|
|
178
|
+
height: number;
|
|
179
|
+
type: "avif";
|
|
180
|
+
}>;
|
|
135
181
|
/**
|
|
136
182
|
*
|
|
137
183
|
* @access package-private
|
|
@@ -154,6 +200,141 @@ declare class Fs extends MimeService {
|
|
|
154
200
|
options?: sharp.ResizeOptions;
|
|
155
201
|
};
|
|
156
202
|
}): Promise<Buffer<ArrayBufferLike>>;
|
|
203
|
+
/**
|
|
204
|
+
* Write data to a file in the system's tmp directory
|
|
205
|
+
* @param filename The filename (can include subdirectories like "img-probe/file.txt")
|
|
206
|
+
* @param data The data to write
|
|
207
|
+
* @param options Optional write stream options
|
|
208
|
+
* @returns The full path to the written file
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const fs = new Fs(process.cwd());
|
|
212
|
+
* const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
|
|
213
|
+
* // Or with a subdirectory:
|
|
214
|
+
* fs.writeTmp("img-probe/output.png", imageBuffer);
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
writeTmp<const F extends string>(filename: F, data: WriteStreamDataShape, options?: WriteStreamOptions): void;
|
|
218
|
+
/**
|
|
219
|
+
* Read a file from the tmp directory
|
|
220
|
+
* @param filename The filename to read (can include subdirectories)
|
|
221
|
+
* @returns Buffer containing the file data
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const fs = new Fs(process.cwd());
|
|
225
|
+
* const data = fs.readTmp("session-data.json");
|
|
226
|
+
* const parsed = JSON.parse(data.toString("utf-8"));
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
readTmp<const F extends string>(filename: F): Buffer<ArrayBuffer>;
|
|
230
|
+
/**
|
|
231
|
+
* Scan the tmp directory for files matching a pattern
|
|
232
|
+
* @param pattern Optional pattern to filter files (e.g., "img-probe")
|
|
233
|
+
* @param options Options for directory reading (defaults to non-recursive to avoid permission issues)
|
|
234
|
+
* @returns Array of matching file paths relative to tmp directory
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const fs = new Fs(process.cwd());
|
|
238
|
+
* // Get all img-probe files
|
|
239
|
+
* const imgFiles = fs.scanTmp("img-probe");
|
|
240
|
+
* // Get all files in tmp (non-recursive)
|
|
241
|
+
* const allFiles = fs.scanTmp();
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
scanTmp(pattern?: string | RegExp, options?: ReadDirOptions): string[];
|
|
245
|
+
/**
|
|
246
|
+
* Extract specific files from tmp directory to a target location
|
|
247
|
+
* @param pattern Pattern to match files (e.g., "img-probe")
|
|
248
|
+
* @param targetDir Target directory to extract files to
|
|
249
|
+
* @param options Options for extraction behavior
|
|
250
|
+
* @returns Array of extracted file paths
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const fs = new Fs(process.cwd());
|
|
254
|
+
* // Extract all img-probe files to ./output
|
|
255
|
+
* const extracted = fs.extractFromTmp("img-probe", "./output");
|
|
256
|
+
* // Extract with custom behavior
|
|
257
|
+
* fs.extractFromTmp("session-", "./sessions", {
|
|
258
|
+
* preserveStructure: true,
|
|
259
|
+
* cleanupAfter: true
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
extractFromTmp(pattern: string, targetDir: string, options?: {
|
|
264
|
+
preserveStructure?: boolean;
|
|
265
|
+
cleanupAfter?: boolean;
|
|
266
|
+
overwrite?: boolean;
|
|
267
|
+
}): string[];
|
|
268
|
+
/**
|
|
269
|
+
* Clean up tmp files matching a pattern
|
|
270
|
+
* @param pattern Pattern to match files for deletion
|
|
271
|
+
* @param maxAge Optional max age in milliseconds (only delete files older than this)
|
|
272
|
+
* @returns Number of files removed
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* const fs = new Fs(process.cwd());
|
|
276
|
+
* // Remove all img-probe files
|
|
277
|
+
* fs.cleanupTmp("img-probe");
|
|
278
|
+
* // Remove session files older than 1 hour
|
|
279
|
+
* fs.cleanupTmp("session-", 60 * 60 * 1000);
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
cleanupTmp(pattern: string, maxAge?: number): number;
|
|
283
|
+
rmTmpFile<const V extends string>(filename: V): void;
|
|
284
|
+
/**
|
|
285
|
+
* Generate a unique tmp filename with optional prefix
|
|
286
|
+
* @param prefix Optional prefix for the filename
|
|
287
|
+
* @param extension Optional file extension (without dot)
|
|
288
|
+
* @returns Unique filename
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* const fs = new Fs(process.cwd());
|
|
292
|
+
* const filename = fs.uniqueTmpName("img-probe", "png");
|
|
293
|
+
* // Returns: "img-probe-1701234567890-a3b2c1.png"
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
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>;
|
|
157
338
|
}
|
|
158
339
|
|
|
159
340
|
export = Fs;
|
package/dist/fs/index.d.ts
CHANGED
|
@@ -2,14 +2,17 @@ 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.js';
|
|
4
4
|
import { MimeService } from '../mime/index.js';
|
|
5
|
+
import '../url/index.js';
|
|
6
|
+
import '../utils/index.js';
|
|
5
7
|
import 'stream';
|
|
6
8
|
import 'buffer';
|
|
7
|
-
import '../url/index.js';
|
|
8
9
|
|
|
9
10
|
declare class Fs extends MimeService {
|
|
10
11
|
cwd: string;
|
|
11
12
|
constructor(cwd: string);
|
|
12
13
|
private get myEnv();
|
|
14
|
+
get tmpDir(): string;
|
|
15
|
+
get tmpDirRelative(): string;
|
|
13
16
|
parseDotEnv(): expand.DotenvExpandOutput;
|
|
14
17
|
/**
|
|
15
18
|
*
|
|
@@ -107,14 +110,15 @@ declare class Fs extends MimeService {
|
|
|
107
110
|
rmdir<const D extends string>(dir: D, options?: RmDirOptions): Promise<void>;
|
|
108
111
|
rmDirSync<const D extends string>(dir: D): void;
|
|
109
112
|
fileToBuffer: <const T extends string>(path: T) => Buffer<ArrayBuffer>;
|
|
113
|
+
fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
|
|
110
114
|
dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
|
|
111
115
|
assetToBuffer<const T extends string>(path: T): Promise<{
|
|
112
|
-
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: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/
|
|
113
|
-
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" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rtf" | "sh" | "sql" | "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";
|
|
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";
|
|
114
118
|
}>;
|
|
115
119
|
assetToBufferView<const T extends string>(path: T): Promise<{
|
|
116
120
|
readonly b64encodedData: 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" | "jar" | "jpeg" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpeg" | "mpkg" | "ndjson" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "png" | "pdf" | "php" | "pkpass" | "ppt" | "pptx" | "py" | "pyc" | "rar" | "rtf" | "sh" | "sql" | "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
|
+
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;
|
|
118
122
|
}>;
|
|
119
123
|
formatHelper<const T extends string>(f: T): string;
|
|
120
124
|
cleanDataUrl<const C extends string>(props: C): string;
|
|
@@ -131,7 +135,49 @@ declare class Fs extends MimeService {
|
|
|
131
135
|
* ✅ 'public/assets/image-1.png'
|
|
132
136
|
*/
|
|
133
137
|
fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
|
|
134
|
-
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param inputUrl remote url to fetch data from
|
|
141
|
+
* @param outputPath desired output path relative to the cwd
|
|
142
|
+
* @param useDetectedExtension optional, defaults to true
|
|
143
|
+
*
|
|
144
|
+
* if `useDetectedExtension` is false you must include the file extension in your output path →
|
|
145
|
+
*
|
|
146
|
+
* 🚫 'public/assets/image-1'
|
|
147
|
+
*
|
|
148
|
+
* ✅ 'public/assets/image-1.png'
|
|
149
|
+
*
|
|
150
|
+
* @description
|
|
151
|
+
* This method is designed for large files that may not fit into memory.
|
|
152
|
+
* It streams the data directly to disk instead of loading it all into memory.
|
|
153
|
+
*/
|
|
154
|
+
fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPathI: O, useDetectedExtension?: boolean): Promise<void>;
|
|
155
|
+
private findBox;
|
|
156
|
+
getImageSize(filePath: string): Promise<{
|
|
157
|
+
width: number;
|
|
158
|
+
height: number;
|
|
159
|
+
type: "png";
|
|
160
|
+
} | {
|
|
161
|
+
width: number;
|
|
162
|
+
height: number;
|
|
163
|
+
type: "jpeg";
|
|
164
|
+
} | {
|
|
165
|
+
width: number;
|
|
166
|
+
height: number;
|
|
167
|
+
type: "gif";
|
|
168
|
+
} | {
|
|
169
|
+
width: number;
|
|
170
|
+
height: number;
|
|
171
|
+
type: "bmp";
|
|
172
|
+
} | {
|
|
173
|
+
width: number;
|
|
174
|
+
height: number;
|
|
175
|
+
type: "webp";
|
|
176
|
+
} | {
|
|
177
|
+
width: number;
|
|
178
|
+
height: number;
|
|
179
|
+
type: "avif";
|
|
180
|
+
}>;
|
|
135
181
|
/**
|
|
136
182
|
*
|
|
137
183
|
* @access package-private
|
|
@@ -154,6 +200,141 @@ declare class Fs extends MimeService {
|
|
|
154
200
|
options?: sharp.ResizeOptions;
|
|
155
201
|
};
|
|
156
202
|
}): Promise<Buffer<ArrayBufferLike>>;
|
|
203
|
+
/**
|
|
204
|
+
* Write data to a file in the system's tmp directory
|
|
205
|
+
* @param filename The filename (can include subdirectories like "img-probe/file.txt")
|
|
206
|
+
* @param data The data to write
|
|
207
|
+
* @param options Optional write stream options
|
|
208
|
+
* @returns The full path to the written file
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* const fs = new Fs(process.cwd());
|
|
212
|
+
* const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
|
|
213
|
+
* // Or with a subdirectory:
|
|
214
|
+
* fs.writeTmp("img-probe/output.png", imageBuffer);
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
writeTmp<const F extends string>(filename: F, data: WriteStreamDataShape, options?: WriteStreamOptions): void;
|
|
218
|
+
/**
|
|
219
|
+
* Read a file from the tmp directory
|
|
220
|
+
* @param filename The filename to read (can include subdirectories)
|
|
221
|
+
* @returns Buffer containing the file data
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const fs = new Fs(process.cwd());
|
|
225
|
+
* const data = fs.readTmp("session-data.json");
|
|
226
|
+
* const parsed = JSON.parse(data.toString("utf-8"));
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
readTmp<const F extends string>(filename: F): Buffer<ArrayBuffer>;
|
|
230
|
+
/**
|
|
231
|
+
* Scan the tmp directory for files matching a pattern
|
|
232
|
+
* @param pattern Optional pattern to filter files (e.g., "img-probe")
|
|
233
|
+
* @param options Options for directory reading (defaults to non-recursive to avoid permission issues)
|
|
234
|
+
* @returns Array of matching file paths relative to tmp directory
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* const fs = new Fs(process.cwd());
|
|
238
|
+
* // Get all img-probe files
|
|
239
|
+
* const imgFiles = fs.scanTmp("img-probe");
|
|
240
|
+
* // Get all files in tmp (non-recursive)
|
|
241
|
+
* const allFiles = fs.scanTmp();
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
scanTmp(pattern?: string | RegExp, options?: ReadDirOptions): string[];
|
|
245
|
+
/**
|
|
246
|
+
* Extract specific files from tmp directory to a target location
|
|
247
|
+
* @param pattern Pattern to match files (e.g., "img-probe")
|
|
248
|
+
* @param targetDir Target directory to extract files to
|
|
249
|
+
* @param options Options for extraction behavior
|
|
250
|
+
* @returns Array of extracted file paths
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const fs = new Fs(process.cwd());
|
|
254
|
+
* // Extract all img-probe files to ./output
|
|
255
|
+
* const extracted = fs.extractFromTmp("img-probe", "./output");
|
|
256
|
+
* // Extract with custom behavior
|
|
257
|
+
* fs.extractFromTmp("session-", "./sessions", {
|
|
258
|
+
* preserveStructure: true,
|
|
259
|
+
* cleanupAfter: true
|
|
260
|
+
* });
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
extractFromTmp(pattern: string, targetDir: string, options?: {
|
|
264
|
+
preserveStructure?: boolean;
|
|
265
|
+
cleanupAfter?: boolean;
|
|
266
|
+
overwrite?: boolean;
|
|
267
|
+
}): string[];
|
|
268
|
+
/**
|
|
269
|
+
* Clean up tmp files matching a pattern
|
|
270
|
+
* @param pattern Pattern to match files for deletion
|
|
271
|
+
* @param maxAge Optional max age in milliseconds (only delete files older than this)
|
|
272
|
+
* @returns Number of files removed
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* const fs = new Fs(process.cwd());
|
|
276
|
+
* // Remove all img-probe files
|
|
277
|
+
* fs.cleanupTmp("img-probe");
|
|
278
|
+
* // Remove session files older than 1 hour
|
|
279
|
+
* fs.cleanupTmp("session-", 60 * 60 * 1000);
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
cleanupTmp(pattern: string, maxAge?: number): number;
|
|
283
|
+
rmTmpFile<const V extends string>(filename: V): void;
|
|
284
|
+
/**
|
|
285
|
+
* Generate a unique tmp filename with optional prefix
|
|
286
|
+
* @param prefix Optional prefix for the filename
|
|
287
|
+
* @param extension Optional file extension (without dot)
|
|
288
|
+
* @returns Unique filename
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* const fs = new Fs(process.cwd());
|
|
292
|
+
* const filename = fs.uniqueTmpName("img-probe", "png");
|
|
293
|
+
* // Returns: "img-probe-1701234567890-a3b2c1.png"
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
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>;
|
|
157
338
|
}
|
|
158
339
|
|
|
159
340
|
export { Fs as default };
|
package/dist/fs/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Fs
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-Y3TLKN7F.js";
|
|
4
|
+
import "../chunk-O4BKLMFV.js";
|
|
5
|
+
import "../chunk-MXEE2WS7.js";
|
|
6
|
+
import "../chunk-QBG7TFHM.js";
|
|
7
|
+
import "../chunk-IUGBPDQJ.js";
|
|
7
8
|
import "../chunk-7QVYU63E.js";
|
|
8
9
|
export {
|
|
9
10
|
Fs as default
|