@d0paminedriven/fs 7.2.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 (44) hide show
  1. package/README.md +104 -51
  2. package/dist/chunk-2IRCHZCF.js +75 -0
  3. package/dist/{chunk-KUGIFRTF.js → chunk-2XQ44ZWR.js} +339 -3
  4. package/dist/{chunk-O2P3L3CJ.js → chunk-6HHKXBIM.js} +5 -2
  5. package/dist/chunk-HPM4IQQR.js +69 -0
  6. package/dist/{chunk-GH6MFTV5.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-MRKO3PAA.js → chunk-R63XI7FS.js} +1 -1
  13. package/dist/{chunk-6FJJLFJL.js → chunk-UW52DMHT.js} +2 -2
  14. package/dist/chunk-Z2WZLZC4.js +75 -0
  15. package/dist/fs/index.d.ts +18 -329
  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 +11 -4
  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 +5 -4
  36. package/dist/mime/index.js +4 -3
  37. package/dist/types/index.d.ts +13 -13
  38. package/dist/types/index.js +1 -1
  39. package/dist/url/index.d.ts +1 -0
  40. package/dist/url/index.js +3 -2
  41. package/dist/utils/index.d.ts +2 -1
  42. package/dist/utils/index.js +2 -1
  43. package/package.json +31 -3
  44. package/dist/chunk-SYISQ57E.js +0 -895
@@ -1,17 +1,24 @@
1
- import { Readable } from 'node:stream';
2
- import { ReadableStream } from 'stream/web';
3
- import expand from 'dotenv-expand';
1
+ import { ImageSpecs } from '../types/index.js';
2
+ import { FsFetch } from '../fs-fetch/index.js';
4
3
  import sharp from 'sharp';
5
- import { ReadDirOptions, ExecuteCommandProps, MkDirSyncOptions, Unit, SizeOpts, WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncDataUnion, WriteFileAsyncOptions, RmDirOptions } from '../types/index.js';
6
- import { Streamable, AsyncIter } from '../types/stream.js';
7
- 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';
8
11
  import '../mime/index.js';
12
+ import '../types/stream.js';
9
13
  import '../url/index.js';
10
14
  import '../utils/index.js';
11
15
  import 'stream';
12
16
  import 'buffer';
17
+ import 'node:stream';
18
+ import 'stream/web';
19
+ import 'dotenv-expand';
13
20
 
14
- declare class Fs extends ImageService {
21
+ declare class Fs extends FsFetch {
15
22
  cwd: string;
16
23
  constructor(cwd: string);
17
24
  getImageSpecs(filePath: string): Promise<{
@@ -161,189 +168,11 @@ declare class Fs extends ImageService {
161
168
  exifDateTimeOriginal: string | null;
162
169
  }>;
163
170
  /**
164
- * Async version of withWs with atomic write support and progress tracking
165
- * @param path Target file path
166
- * @param data Streamable data to write
167
- * @param options Optional atomic write and abort signal
168
- * @returns Promise with path and bytes written
169
- * @example
170
- * ```ts
171
- * const fs = new Fs(process.cwd());
172
- * // Simple async write
173
- * const result = await fs.asyncWithWs("output.txt", "Hello World");
174
- * console.log(`Wrote ${result.bytes} bytes to ${result.path}`);
175
- *
176
- * // Atomic write with temp file
177
- * const { path, bytes } = await fs.asyncWithWs(
178
- * "critical-data.json",
179
- * JSON.stringify(data),
180
- * { atomic: true }
181
- * );
182
- * ```
183
- */
184
- asyncWithWs(path: string, data: Streamable, options?: {
185
- atomic?: boolean;
186
- signal?: AbortSignal;
187
- }): Promise<string | {
188
- path: string;
189
- bytes: number;
190
- newPath?: undefined;
191
- newBytes?: undefined;
192
- } | {
193
- path: string;
194
- bytes: number;
195
- newPath: string;
196
- newBytes: number;
197
- } | undefined>;
198
- private get myEnv();
199
- get tmpDir(): string;
200
- get tmpDirRelative(): string;
201
- parseDotEnv(): expand.DotenvExpandOutput;
202
- isUint8Array(v: unknown): v is Uint8Array<ArrayBufferLike>;
203
- isBuffer(v: unknown): v is Buffer<ArrayBufferLike>;
204
- isWebReadableStream(v: unknown): v is ReadableStream<any>;
205
- isAsyncIterable(v: unknown): v is AsyncIter;
206
- toReadable(data: Streamable): Readable;
207
- /**
208
- *
209
- * @param target path to the file or directory to check for existence
210
- * @returns true if the file or directory exists, false otherwise
211
- * @example
212
- * ```ts
213
- * const fs = new Fs(process.cwd());
214
- * const exists = fs.exists("my-file.txt");
215
- * console.log(exists); // true if the file exists, false otherwise
216
- * ```
217
- * @description
218
- * This method checks if a file or directory exists at the specified path input
219
- *
220
- * Additional Note:
221
- *
222
- * say you have a directory that begins with a dot, such as `.turbo`;
223
- *
224
- * in this scenario, both `./.turbo` and `.turbo` will return true if the directory exists
225
- *
226
- */
227
- exists<const T extends string>(target: T): boolean;
228
- /**
229
- *
230
- * @param ms milliseconds to wait
231
- * @returns a promise that resolves after the specified number of milliseconds
232
- * @example
233
- * ```ts
234
- * const fs = new Fs(process.cwd());
235
- * await fs.wait(1000); // waits for 1 second
236
- * console.log("Done waiting!");
237
- * ```
238
- *
239
- * Alternatively, you can use it like this:
240
- * ```ts
241
- * const fs = new Fs(process.cwd());
242
- * fs.wait(1000).then(() => { // waits for 1 second
243
- * console.log("Done waiting!");
244
- * // do something after waiting
245
- * });
246
- * ```
247
- *
248
- * @description
249
- * 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.
250
- */
251
- wait<T extends number>(ms: T): Promise<unknown>;
252
- /**
253
- * Handles an array or readonly array of strings and/or Buffers, converting Buffers to strings
254
- * @param arr An array or readonly array of strings and/or Buffers
255
- * @returns An array of strings with Buffers converted to UTF-8 strings.
256
- */
257
- handleBuffStrArrUnion<const T extends (string | Buffer)[] | readonly (string | Buffer)[]>(arr: T): string[];
258
- isRootPathTargeted<const T extends string>(path: T): boolean;
259
- /**
260
- *
261
- * @param path path to the directory relative to the cwd
262
- * @param options options for reading the directory, defaults to recursive
263
- *
264
- * The following two examples are equivalent:
265
- *
266
- * @example
267
- * ```ts
268
- * const fs = new Fs(process.cwd());
269
- * const files = fs.readDir("./my-directory", { recursive: true });
270
- * console.log(files);
271
- * ```
272
- * @example
273
- * ```ts
274
- * const fs = new Fs(process.cwd());
275
- * const files = fs.readDir("my-directory", { recursive: true });
276
- * console.log(files);
277
- * ```
278
- *
279
- * @returns an array of strings representing the contents of the directory
280
- */
281
- readDir<const T extends string>(path: T, options?: ReadDirOptions): string[];
282
- executeCommand: <const T extends string>({ command, ...options }: ExecuteCommandProps<T>) => string;
283
- existsSync<const T extends string>(path: T): boolean;
284
- pathHandler<const T extends string>(path: T): string;
285
- mkdirSync<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
286
- private units;
287
- private u;
288
- autoFileSizeRaw(size: number | bigint): {
289
- value: number;
290
- unit: "B" | "KB" | "MB" | "GB" | "TB" | "PB" | undefined;
291
- };
292
- getSize<const S extends Unit | Lowercase<Unit> | "auto">(size: number | bigint, target: S, opts?: SizeOpts): string | number;
293
- fileSizeMb<const T extends string>(path: T): number;
294
- fileSize<const T extends string, const S extends Unit | Lowercase<Unit> | "auto">(path: T, target: S, opts?: SizeOpts): string | number;
295
- generateDirIfDNE<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
296
- withWs<const T extends string>(path: T, data: WriteStreamDataShape, options?: WriteStreamOptions): string | boolean | undefined;
297
- writeFileAsync: <const T extends string>(path: T, data: WriteFileAsyncDataUnion, options?: WriteFileAsyncOptions) => Promise<string | void>;
298
- unlink<const P extends string>(path: P): Promise<void>;
299
- rmFile<const FP extends string>(filePath: FP): void;
300
- rmdir<const D extends string>(dir: D, options?: RmDirOptions): Promise<void>;
301
- rmDirSync<const D extends string>(dir: D): void;
302
- fileToBuffer: <const T extends string>(path: T) => Buffer<ArrayBuffer>;
303
- fileToBufferAsync: <const T extends string>(path: T) => Promise<Buffer<ArrayBufferLike>>;
304
- dirContainsDir<const From extends string, const To extends string>(readDir: From, targetDir: To, options?: ReadDirOptions): boolean;
305
- assetToBuffer<const T extends string>(path: T): Promise<{
306
- 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: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}`;
307
- readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "aac" | "abw" | "aces" | "apng" | "arc" | "avci" | "avi" | "azw" | "bin" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "cur" | "doc" | "docx" | "dpx" | "emf" | "eot" | "epub" | "glb" | "gltf" | "gz" | "hjif" | "hmpg" | "htm" | "html" | "ico" | "ics" | "ivs" | "ivt" | "jar" | "jfif" | "jif" | "jpe" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpd" | "mpeg" | "mpkg" | "mtlx" | "ndjson" | "node" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "pdf" | "php" | "pjp" | "pjpeg" | "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" | "webm" | "webmanifest" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "yaml" | "yml" | "zip" | "3gp" | "3g2" | "7z";
308
- }>;
309
- assetToBufferView<const T extends string>(path: T): Promise<{
310
- readonly b64encodedData: string;
311
- readonly extension: "png" | "jpeg" | "gif" | "bmp" | "webp" | "avif" | "aac" | "abw" | "aces" | "apng" | "arc" | "avci" | "avi" | "azw" | "bin" | "bz" | "bz2" | "cda" | "cjs" | "csh" | "css" | "csv" | "cur" | "doc" | "docx" | "dpx" | "emf" | "eot" | "epub" | "glb" | "gltf" | "gz" | "hjif" | "hmpg" | "htm" | "html" | "ico" | "ics" | "ivs" | "ivt" | "jar" | "jfif" | "jif" | "jpe" | "jpg" | "js" | "json" | "jsonld" | "ktx" | "ktx2" | "m3u8" | "m4a" | "m4v" | "md" | "mdx" | "mid" | "midi" | "mjs" | "mp3" | "mp4" | "mpd" | "mpeg" | "mpkg" | "mtlx" | "ndjson" | "node" | "obj" | "odp" | "ods" | "odt" | "oga" | "ogg" | "ogv" | "ogx" | "opus" | "otf" | "pdf" | "php" | "pjp" | "pjpeg" | "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" | "webm" | "webmanifest" | "woff" | "woff2" | "xhtml" | "xls" | "xlsx" | "xml" | "xul" | "yaml" | "yml" | "zip" | "3gp" | "3g2" | "7z" | undefined;
312
- }>;
313
- formatHelper<const T extends string>(f: T): string;
314
- cleanDataUrl<const C extends string>(props: C): string;
315
- /**
316
- *
317
- * @param inputUrl remote url to fetch data from
318
- * @param outputPath desired output path relative to the cwd
319
- * @param useDetectedExtension optional, defaults to true
320
- *
321
- * if `useDetectedExtension` is false you must include the file extension in your output path &rarr;
322
- *
323
- * 🚫 'public/assets/image-1'
324
- *
325
- * ✅ 'public/assets/image-1.png'
171
+ * Extract image metadata using streaming (only reads ~4KB)
172
+ * Much more memory efficient for large images
326
173
  */
327
- fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
328
- private knownToBlockHead;
329
- /**
330
- *
331
- * @param inputUrl remote url to fetch data from
332
- * @param outputPath desired output path relative to the cwd
333
- * @param useDetectedExtension optional, defaults to true
334
- *
335
- * if `useDetectedExtension` is false you must include the file extension in your output path &rarr;
336
- *
337
- * 🚫 'public/assets/image-1'
338
- *
339
- * ✅ 'public/assets/image-1.png'
340
- *
341
- * @description
342
- * This method is designed for all files regardless of size, but especially for
343
- * larger files that may not fit into memory (it intelligently determines the best approach on the fly)
344
- * For files > 100 MB, it streams the data directly to disk instead of loading it all into memory
345
- */
346
- 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>;
347
176
  /**
348
177
  *
349
178
  * @access package-private
@@ -366,146 +195,6 @@ declare class Fs extends ImageService {
366
195
  options?: sharp.ResizeOptions;
367
196
  };
368
197
  }): Promise<Buffer<ArrayBufferLike>>;
369
- existsTmp(path: string): boolean;
370
- mkdirTmp(path: string, options?: MkDirSyncOptions): string | undefined;
371
- generateDirIfDNETmp<const T extends string>(path: T, options?: MkDirSyncOptions): string | undefined;
372
- /**
373
- * Write data to a file in the system's tmp directory
374
- * @param filename The filename (can include subdirectories like "img-probe/file.txt")
375
- * @param data The data to write
376
- * @param options Optional write stream options
377
- * @returns The full path to the written file
378
- * @example
379
- * ```ts
380
- * const fs = new Fs(process.cwd());
381
- * const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
382
- * // Or with a subdirectory:
383
- * fs.writeTmp("img-probe/output.png", imageBuffer);
384
- * ```
385
- */
386
- writeTmp<const F extends string>(filename: F, data: WriteStreamDataShape, options?: WriteStreamOptions): void;
387
- writeTmpAsync<const F extends string>(filename: F, data: string, options?: WriteFileAsyncOptions): Promise<string | void>;
388
- readTmpAsync<const F extends string>(filename: F): Promise<Buffer<ArrayBufferLike>>;
389
- /**
390
- * Read a file from the tmp directory
391
- * @param filename The filename to read (can include subdirectories)
392
- * @returns Buffer containing the file data
393
- * @example
394
- * ```ts
395
- * const fs = new Fs(process.cwd());
396
- * const data = fs.readTmp("session-data.json");
397
- * const parsed = JSON.parse(data.toString("utf-8"));
398
- * ```
399
- */
400
- readTmp<const F extends string>(filename: F): Buffer<ArrayBuffer>;
401
- /**
402
- * Scan the tmp directory for files matching a pattern
403
- * @param pattern Optional pattern to filter files (e.g., "img-probe")
404
- * @param options Options for directory reading (defaults to non-recursive to avoid permission issues)
405
- * @returns Array of matching file paths relative to tmp directory
406
- * @example
407
- * ```ts
408
- * const fs = new Fs(process.cwd());
409
- * // Get all img-probe files
410
- * const imgFiles = fs.scanTmp("img-probe");
411
- * // Get all files in tmp (non-recursive)
412
- * const allFiles = fs.scanTmp();
413
- * ```
414
- */
415
- scanTmp(pattern?: string | RegExp, options?: ReadDirOptions): string[];
416
- /**
417
- * Extract specific files from tmp directory to a target location
418
- * @param pattern Pattern to match files (e.g., "img-probe")
419
- * @param targetDir Target directory to extract files to
420
- * @param options Options for extraction behavior
421
- * @returns Array of extracted file paths
422
- * @example
423
- * ```ts
424
- * const fs = new Fs(process.cwd());
425
- * // Extract all img-probe files to ./output
426
- * const extracted = fs.extractFromTmp("img-probe", "./output");
427
- * // Extract with custom behavior
428
- * fs.extractFromTmp("session-", "./sessions", {
429
- * preserveStructure: true,
430
- * cleanupAfter: true
431
- * });
432
- * ```
433
- */
434
- extractFromTmp(pattern: string, targetDir: string, options?: {
435
- preserveStructure?: boolean;
436
- cleanupAfter?: boolean;
437
- overwrite?: boolean;
438
- }): string[];
439
- /**
440
- * Clean up tmp files matching a pattern
441
- * @param pattern Pattern to match files for deletion
442
- * @param maxAge Optional max age in milliseconds (only delete files older than this)
443
- * @returns Number of files removed
444
- * @example
445
- * ```ts
446
- * const fs = new Fs(process.cwd());
447
- * // Remove all img-probe files
448
- * fs.cleanupTmp("img-probe");
449
- * // Remove session files older than 1 hour
450
- * fs.cleanupTmp("session-", 60 * 60 * 1000);
451
- * ```
452
- */
453
- cleanupTmp(pattern: string, maxAge?: number): number;
454
- rmTmpFile<const V extends string>(filename: V): void;
455
- /**
456
- * Generate a unique tmp filename with optional prefix
457
- * @param prefix Optional prefix for the filename
458
- * @param extension Optional file extension (without dot)
459
- * @returns Unique filename
460
- * @example
461
- * ```ts
462
- * const fs = new Fs(process.cwd());
463
- * const filename = fs.uniqueTmpName("img-probe", "png");
464
- * // Returns: "img-probe-1701234567890-a3b2c1.png"
465
- * ```
466
- */
467
- uniqueTmpName(prefix?: string, extension?: string): string;
468
- /**
469
- * Async generator for cleaning tmp files with batched removal
470
- * @param pattern Pattern to match files for deletion
471
- * @param batchSize Number of files to remove per batch (default 10)
472
- * @yields Progress information during cleanup
473
- * @returns Final cleanup summary
474
- * @example
475
- * ```ts
476
- * const fs = new Fs(process.cwd());
477
- * // Clean up with progress tracking
478
- * for await (const progress of fs.cleanTmpGenerator("session-", 25)) {
479
- * console.log(progress);
480
- * }
481
- * ```
482
- */
483
- cleanTmpGenerator(pattern: string | RegExp, batchSize?: number): AsyncGenerator<{
484
- action: "removing";
485
- batch: string[];
486
- batchNumber: number;
487
- totalBatches: number;
488
- totalFound: number;
489
- removed: number;
490
- batchSize?: undefined;
491
- totalRemoved?: undefined;
492
- remaining?: undefined;
493
- } | {
494
- action: "batch-complete";
495
- batchNumber: number;
496
- batchSize: number;
497
- totalRemoved: number;
498
- remaining: number;
499
- batch?: undefined;
500
- totalBatches?: undefined;
501
- totalFound?: undefined;
502
- removed?: undefined;
503
- }, {
504
- action: "complete";
505
- totalRemoved: number;
506
- totalBatches: number;
507
- pattern: string;
508
- }, unknown>;
509
198
  }
510
199
 
511
200
  export { Fs as default };
package/dist/fs/index.js CHANGED
@@ -1,11 +1,18 @@
1
1
  import {
2
2
  Fs
3
- } from "../chunk-SYISQ57E.js";
4
- import "../chunk-KUGIFRTF.js";
5
- import "../chunk-GH6MFTV5.js";
6
- import "../chunk-MRKO3PAA.js";
7
- import "../chunk-6FJJLFJL.js";
8
- import "../chunk-O2P3L3CJ.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