@d0paminedriven/fs 7.1.0 → 7.3.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.
Files changed (60) hide show
  1. package/README.md +104 -51
  2. package/dist/chunk-2IRCHZCF.js +75 -0
  3. package/dist/{chunk-LFHV4PPA.js → chunk-2XQ44ZWR.js} +339 -3
  4. package/dist/{chunk-IUGBPDQJ.js → chunk-6HHKXBIM.js} +5 -2
  5. package/dist/chunk-HPM4IQQR.js +69 -0
  6. package/dist/{chunk-3WB2TSBO.js → chunk-KNLXF622.js} +2 -2
  7. package/dist/chunk-KOKPGEU4.js +69 -0
  8. package/dist/chunk-LQP2FYMK.js +237 -0
  9. package/dist/chunk-NHYRCNMW.js +107 -0
  10. package/dist/chunk-NOOFSAF4.js +165 -0
  11. package/dist/chunk-PTXZQBLV.js +367 -0
  12. package/dist/{chunk-RJ2YQE3C.js → chunk-R63XI7FS.js} +1 -1
  13. package/dist/{chunk-QBG7TFHM.js → chunk-UW52DMHT.js} +2 -2
  14. package/dist/chunk-Z2WZLZC4.js +75 -0
  15. package/dist/fs/index.d.ts +18 -282
  16. package/dist/fs/index.js +13 -6
  17. package/dist/fs-atomic/index.d.ts +38 -0
  18. package/dist/fs-atomic/index.js +14 -0
  19. package/dist/fs-base/index.d.ts +112 -0
  20. package/dist/fs-base/index.js +13 -0
  21. package/dist/fs-core/index.d.ts +24 -0
  22. package/dist/fs-core/index.js +17 -0
  23. package/dist/fs-fetch/index.d.ts +64 -0
  24. package/dist/fs-fetch/index.js +19 -0
  25. package/dist/fs-size/index.d.ts +30 -0
  26. package/dist/fs-size/index.js +16 -0
  27. package/dist/fs-tmp/index.d.ts +194 -0
  28. package/dist/fs-tmp/index.js +18 -0
  29. package/dist/image/index.d.ts +35 -1
  30. package/dist/image/index.js +5 -4
  31. package/dist/index.d.ts +12 -2
  32. package/dist/index.js +36 -8
  33. package/dist/ld/index.d.ts +14 -0
  34. package/dist/ld/index.js +8 -0
  35. package/dist/mime/index.d.ts +1 -0
  36. package/dist/mime/index.js +4 -3
  37. package/dist/types/index.d.ts +12 -12
  38. package/dist/types/index.js +1 -1
  39. package/dist/types/stream.d.ts +9 -0
  40. package/dist/types/stream.js +1 -0
  41. package/dist/url/index.d.ts +1 -0
  42. package/dist/url/index.js +3 -2
  43. package/dist/utils/index.d.ts +2 -1
  44. package/dist/utils/index.js +2 -1
  45. package/package.json +37 -5
  46. package/dist/chunk-3REIEDSC.js +0 -745
  47. package/dist/fs/index.cjs +0 -1818
  48. package/dist/fs/index.d.cts +0 -464
  49. package/dist/image/index.cjs +0 -1071
  50. package/dist/image/index.d.cts +0 -88
  51. package/dist/index.cjs +0 -1838
  52. package/dist/index.d.cts +0 -10
  53. package/dist/mime/index.cjs +0 -509
  54. package/dist/mime/index.d.cts +0 -502
  55. package/dist/types/index.cjs +0 -38
  56. package/dist/types/index.d.cts +0 -333
  57. package/dist/url/index.cjs +0 -181
  58. package/dist/url/index.d.cts +0 -33
  59. package/dist/utils/index.cjs +0 -157
  60. package/dist/utils/index.d.cts +0 -25
@@ -1,14 +1,24 @@
1
- import expand from 'dotenv-expand';
1
+ import { ImageSpecs } from '../types/index.js';
2
+ import { FsFetch } from '../fs-fetch/index.js';
2
3
  import sharp from 'sharp';
3
- import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, Unit, SizeOpts, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.js';
4
- import { ImageService } from '../image/index.js';
4
+ import '../fs-atomic/index.js';
5
+ import '../fs-base/index.js';
6
+ import '../fs-core/index.js';
7
+ import '../fs-size/index.js';
8
+ import '../fs-tmp/index.js';
9
+ import '../image/index.js';
10
+ import '../ld/index.js';
5
11
  import '../mime/index.js';
12
+ import '../types/stream.js';
6
13
  import '../url/index.js';
7
14
  import '../utils/index.js';
8
15
  import 'stream';
9
16
  import 'buffer';
17
+ import 'node:stream';
18
+ import 'stream/web';
19
+ import 'dotenv-expand';
10
20
 
11
- declare class Fs extends ImageService {
21
+ declare class Fs extends FsFetch {
12
22
  cwd: string;
13
23
  constructor(cwd: string);
14
24
  getImageSpecs(filePath: string): Promise<{
@@ -157,150 +167,12 @@ declare class Fs extends ImageService {
157
167
  iccProfile: string | null;
158
168
  exifDateTimeOriginal: string | null;
159
169
  }>;
160
- private get myEnv();
161
- get tmpDir(): string;
162
- get tmpDirRelative(): string;
163
- parseDotEnv(): expand.DotenvExpandOutput;
164
170
  /**
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
171
+ * Extract image metadata using streaming (only reads ~4KB)
172
+ * Much more memory efficient for large images
302
173
  */
303
- fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPathI: O, useDetectedExtension?: boolean): Promise<void>;
174
+ getImageSpecsStream(filePath: string): Promise<ImageSpecs>;
175
+ getImageSpecsStreamTmp(filePath: string): Promise<ImageSpecs>;
304
176
  /**
305
177
  *
306
178
  * @access package-private
@@ -323,142 +195,6 @@ declare class Fs extends ImageService {
323
195
  options?: sharp.ResizeOptions;
324
196
  };
325
197
  }): 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
198
  }
463
199
 
464
200
  export { Fs as default };
package/dist/fs/index.js CHANGED
@@ -1,11 +1,18 @@
1
1
  import {
2
2
  Fs
3
- } from "../chunk-3REIEDSC.js";
4
- import "../chunk-LFHV4PPA.js";
5
- import "../chunk-3WB2TSBO.js";
6
- import "../chunk-RJ2YQE3C.js";
7
- import "../chunk-QBG7TFHM.js";
8
- import "../chunk-IUGBPDQJ.js";
3
+ } from "../chunk-HPM4IQQR.js";
4
+ import "../chunk-NOOFSAF4.js";
5
+ import "../chunk-PTXZQBLV.js";
6
+ import "../chunk-KOKPGEU4.js";
7
+ import "../chunk-2IRCHZCF.js";
8
+ import "../chunk-R63XI7FS.js";
9
+ import "../chunk-NHYRCNMW.js";
10
+ import "../chunk-LQP2FYMK.js";
11
+ import "../chunk-2XQ44ZWR.js";
12
+ import "../chunk-KNLXF622.js";
13
+ import "../chunk-UW52DMHT.js";
14
+ import "../chunk-6HHKXBIM.js";
15
+ import "../chunk-Z2WZLZC4.js";
9
16
  import "../chunk-7QVYU63E.js";
10
17
  export {
11
18
  Fs as default
@@ -0,0 +1,38 @@
1
+ import { ExecuteCommandProps, MkDirSyncOptions, ReadDirOptions, RmOptions, NoParamCallback } from '../types/index.js';
2
+ import { FsBase } from '../fs-base/index.js';
3
+ import 'stream';
4
+ import 'buffer';
5
+ import 'node:stream';
6
+ import 'stream/web';
7
+ import 'dotenv-expand';
8
+ import '../types/stream.js';
9
+ import '../image/index.js';
10
+ import '../mime/index.js';
11
+ import '../url/index.js';
12
+ import '../utils/index.js';
13
+ import '../ld/index.js';
14
+
15
+ declare class FsAtomic extends FsBase {
16
+ cwd: string;
17
+ constructor(cwd: string);
18
+ executeCommand: <const T extends string>({ command, ...options }: ExecuteCommandProps<T>) => string;
19
+ mkdirSync<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
20
+ generateDirIfDNE<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
21
+ fileToBuffer: <const T extends string>(path: T) => Buffer<ArrayBuffer>;
22
+ fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
23
+ dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
24
+ rmFile<const FP extends string>(filePath: FP, options?: RmOptions): void;
25
+ /**
26
+ * Removes files and directories (modeled on the standard POSIX `rm` utility).
27
+ * To get a behavior similar to the `rm -rf` Unix command, use options `{ recursive: true, force: true }`.
28
+ * @return Fulfills with `undefined` upon success.
29
+ */
30
+ rmdir<const D extends string>(dir: D, options?: RmOptions): Promise<void>;
31
+ rmDirSync<const D extends string>(dir: D, options?: RmOptions, callback?: NoParamCallback): void;
32
+ existsTmp(path: string): boolean;
33
+ mkdirTmp(path: string, options?: MkDirSyncOptions): string | undefined;
34
+ generateDirIfDNETmp<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
35
+ rmTmpFile<const V extends string>(filename: V): void;
36
+ }
37
+
38
+ export { FsAtomic };
@@ -0,0 +1,14 @@
1
+ import {
2
+ FsAtomic
3
+ } from "../chunk-NHYRCNMW.js";
4
+ import "../chunk-LQP2FYMK.js";
5
+ import "../chunk-2XQ44ZWR.js";
6
+ import "../chunk-KNLXF622.js";
7
+ import "../chunk-UW52DMHT.js";
8
+ import "../chunk-6HHKXBIM.js";
9
+ import "../chunk-Z2WZLZC4.js";
10
+ import "../chunk-7QVYU63E.js";
11
+ export {
12
+ FsAtomic
13
+ };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,112 @@
1
+ import { Readable } from 'node:stream';
2
+ import { ReadableStream } from 'stream/web';
3
+ import expand from 'dotenv-expand';
4
+ import { ReadDirOptions } from '../types/index.js';
5
+ import { AsyncIter, Streamable } from '../types/stream.js';
6
+ import { ImageService } from '../image/index.js';
7
+ import 'stream';
8
+ import 'buffer';
9
+ import '../mime/index.js';
10
+ import '../url/index.js';
11
+ import '../utils/index.js';
12
+ import '../ld/index.js';
13
+
14
+ declare class FsBase extends ImageService {
15
+ cwd: string;
16
+ constructor(cwd: string);
17
+ get tmpDir(): string;
18
+ get homeDir(): string;
19
+ get platform(): NodeJS.Platform;
20
+ get hostname(): string;
21
+ get devNull(): string;
22
+ get eol(): string;
23
+ private get env();
24
+ parseDotEnv(): expand.DotenvParseOutput | undefined;
25
+ relative(from: string, to: string): string;
26
+ isHomeTargeted(path: string): true | undefined;
27
+ isRootPathTargeted<const T extends string>(path: T): boolean;
28
+ pathHandler<const T extends string>(path: T): string;
29
+ isUint8Array(v: unknown): v is Uint8Array<ArrayBufferLike>;
30
+ isBuffer(v: unknown): v is Buffer<ArrayBufferLike>;
31
+ isWebReadableStream(v: unknown): v is ReadableStream<any>;
32
+ isAsyncIterable(v: unknown): v is AsyncIter;
33
+ formatHelper<const T extends string>(f: T): string;
34
+ cleanDataUrl<const C extends string>(props: C): string;
35
+ toReadable(data: Streamable): Readable;
36
+ /**
37
+ *
38
+ * @param target path to the file or directory to check for existence
39
+ * @returns true if the file or directory exists, false otherwise
40
+ * @example
41
+ * ```ts
42
+ * const fs = new Fs(process.cwd());
43
+ * const exists = fs.exists("my-file.txt");
44
+ * console.log(exists); // true if the file exists, false otherwise
45
+ * ```
46
+ * @description
47
+ * This method checks if a file or directory exists at the specified path input
48
+ *
49
+ * Additional Note:
50
+ *
51
+ * say you have a directory that begins with a dot, such as `.turbo`;
52
+ *
53
+ * in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
54
+ *
55
+ */
56
+ exists<const T extends string>(target: T): boolean;
57
+ /**
58
+ *
59
+ * @param ms milliseconds to wait
60
+ * @returns a promise that resolves after the specified number of milliseconds
61
+ * @example
62
+ * ```ts
63
+ * const fs = new Fs(process.cwd());
64
+ * await fs.wait(1000); // waits for 1 second
65
+ * console.log("Done waiting!");
66
+ * ```
67
+ *
68
+ * Alternatively, you can use it like this:
69
+ * ```ts
70
+ * const fs = new Fs(process.cwd());
71
+ * fs.wait(1000).then(() => { // waits for 1 second
72
+ * console.log("Done waiting!");
73
+ * // do something after waiting
74
+ * });
75
+ * ```
76
+ *
77
+ * @description
78
+ * 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.
79
+ */
80
+ wait<T extends number>(ms: T): Promise<unknown>;
81
+ /**
82
+ * Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
83
+ * @param arr An array or readonly array of strings and/or Buffers
84
+ * @returns An array of strings with Buffers converted to UTF-8 strings.
85
+ */
86
+ handleBuffStrArrUnion<const T extends (string | Buffer)[] | readonly (string | Buffer)[]>(arr: T): string[];
87
+ /**
88
+ *
89
+ * @param path path to the directory relative to the cwd
90
+ * @param options options for reading the directory, defaults to recursive
91
+ *
92
+ * The following two examples are equivalent:
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const fs = new Fs(process.cwd());
97
+ * const files = fs.readDir("./my-directory", { recursive: true });
98
+ * console.log(files);
99
+ * ```
100
+ * @example
101
+ * ```ts
102
+ * const fs = new Fs(process.cwd());
103
+ * const files = fs.readDir("my-directory", { recursive: true });
104
+ * console.log(files);
105
+ * ```
106
+ *
107
+ * @returns an array of strings representing the contents of the directory
108
+ */
109
+ readDir<const T extends string>(path: T, options?: ReadDirOptions): string[];
110
+ }
111
+
112
+ export { FsBase };
@@ -0,0 +1,13 @@
1
+ import {
2
+ FsBase
3
+ } from "../chunk-LQP2FYMK.js";
4
+ import "../chunk-2XQ44ZWR.js";
5
+ import "../chunk-KNLXF622.js";
6
+ import "../chunk-UW52DMHT.js";
7
+ import "../chunk-6HHKXBIM.js";
8
+ import "../chunk-Z2WZLZC4.js";
9
+ import "../chunk-7QVYU63E.js";
10
+ export {
11
+ FsBase
12
+ };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,24 @@
1
+ import { FsSize } from '../fs-size/index.js';
2
+ import { WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions } from '../types/index.js';
3
+ import '../fs-atomic/index.js';
4
+ import '../fs-base/index.js';
5
+ import 'node:stream';
6
+ import 'stream/web';
7
+ import 'dotenv-expand';
8
+ import '../types/stream.js';
9
+ import '../image/index.js';
10
+ import '../mime/index.js';
11
+ import '../url/index.js';
12
+ import '../utils/index.js';
13
+ import '../ld/index.js';
14
+ import 'stream';
15
+ import 'buffer';
16
+
17
+ declare class FsCore extends FsSize {
18
+ cwd: string;
19
+ constructor(cwd: string);
20
+ withWs<const T extends string>(path: T, data: WriteStreamDataShape, options?: WriteStreamOptions): string | boolean | undefined;
21
+ writeFileAsync: <const T extends string>(path: T, data: WriteFileAsyncDataUnion, options?: WriteFileAsyncOptions) => Promise<string | void>;
22
+ }
23
+
24
+ export { FsCore };
@@ -0,0 +1,17 @@
1
+ import {
2
+ FsCore
3
+ } from "../chunk-KOKPGEU4.js";
4
+ import "../chunk-2IRCHZCF.js";
5
+ import "../chunk-R63XI7FS.js";
6
+ import "../chunk-NHYRCNMW.js";
7
+ import "../chunk-LQP2FYMK.js";
8
+ import "../chunk-2XQ44ZWR.js";
9
+ import "../chunk-KNLXF622.js";
10
+ import "../chunk-UW52DMHT.js";
11
+ import "../chunk-6HHKXBIM.js";
12
+ import "../chunk-Z2WZLZC4.js";
13
+ import "../chunk-7QVYU63E.js";
14
+ export {
15
+ FsCore
16
+ };
17
+ //# sourceMappingURL=index.js.map