@d0paminedriven/fs 7.2.0 → 7.4.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 (45) hide show
  1. package/README.md +127 -51
  2. package/dist/{chunk-O2P3L3CJ.js → chunk-6HHKXBIM.js} +5 -2
  3. package/dist/chunk-7FHBNIB7.js +240 -0
  4. package/dist/{chunk-KUGIFRTF.js → chunk-C2ANVZLG.js} +345 -4
  5. package/dist/chunk-FPB77OGJ.js +75 -0
  6. package/dist/chunk-IU4MDHYM.js +75 -0
  7. package/dist/chunk-KDWGS5GC.js +69 -0
  8. package/dist/{chunk-GH6MFTV5.js → chunk-KNLXF622.js} +2 -2
  9. package/dist/chunk-Q2VF3BVH.js +165 -0
  10. package/dist/{chunk-MRKO3PAA.js → chunk-R63XI7FS.js} +1 -1
  11. package/dist/chunk-TDMPLELZ.js +367 -0
  12. package/dist/{chunk-6FJJLFJL.js → chunk-UW52DMHT.js} +2 -2
  13. package/dist/chunk-XCA34DKZ.js +107 -0
  14. package/dist/chunk-Z2WZLZC4.js +75 -0
  15. package/dist/fs/index.d.ts +21 -476
  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 +36 -2
  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/types/stream.d.ts +2 -1
  40. package/dist/url/index.d.ts +1 -0
  41. package/dist/url/index.js +3 -2
  42. package/dist/utils/index.d.ts +2 -1
  43. package/dist/utils/index.js +2 -1
  44. package/package.json +32 -4
  45. package/dist/chunk-SYISQ57E.js +0 -895
@@ -0,0 +1,14 @@
1
+ import {
2
+ FsAtomic
3
+ } from "../chunk-XCA34DKZ.js";
4
+ import "../chunk-7FHBNIB7.js";
5
+ import "../chunk-C2ANVZLG.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): boolean;
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-7FHBNIB7.js";
4
+ import "../chunk-C2ANVZLG.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-KDWGS5GC.js";
4
+ import "../chunk-FPB77OGJ.js";
5
+ import "../chunk-R63XI7FS.js";
6
+ import "../chunk-XCA34DKZ.js";
7
+ import "../chunk-7FHBNIB7.js";
8
+ import "../chunk-C2ANVZLG.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
@@ -0,0 +1,64 @@
1
+ import { FsTmp } from '../fs-tmp/index.js';
2
+ import '../types/index.js';
3
+ import 'stream';
4
+ import 'buffer';
5
+ import '../fs-core/index.js';
6
+ import '../fs-size/index.js';
7
+ import '../fs-atomic/index.js';
8
+ import '../fs-base/index.js';
9
+ import 'node:stream';
10
+ import 'stream/web';
11
+ import 'dotenv-expand';
12
+ import '../types/stream.js';
13
+ import '../image/index.js';
14
+ import '../mime/index.js';
15
+ import '../url/index.js';
16
+ import '../utils/index.js';
17
+ import '../ld/index.js';
18
+
19
+ declare class FsFetch extends FsTmp {
20
+ cwd: string;
21
+ constructor(cwd: string);
22
+ assetToBuffer<const T extends string>(path: T): Promise<{
23
+ 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}`;
24
+ 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";
25
+ }>;
26
+ assetToBufferView<const T extends string>(path: T): Promise<{
27
+ readonly b64encodedData: string;
28
+ 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;
29
+ }>;
30
+ /**
31
+ *
32
+ * @param inputUrl remote url to fetch data from
33
+ * @param outputPath desired output path relative to the cwd
34
+ * @param useDetectedExtension optional, defaults to true
35
+ *
36
+ * if `useDetectedExtension` is false you must include the file extension in your output path &rarr;
37
+ *
38
+ * 🚫 'public/assets/image-1'
39
+ *
40
+ * ✅ 'public/assets/image-1.png'
41
+ */
42
+ fetchRemoteWriteLocal<const I extends string, const O extends string>(inputUrl: I, outputPath: O, useDetectedExtension?: boolean): Promise<void>;
43
+ private knownToBlockHead;
44
+ /**
45
+ *
46
+ * @param inputUrl remote url to fetch data from
47
+ * @param outputPath desired output path relative to the cwd
48
+ * @param useDetectedExtension optional, defaults to true
49
+ *
50
+ * if `useDetectedExtension` is false you must include the file extension in your output path &rarr;
51
+ *
52
+ * 🚫 'public/assets/image-1'
53
+ *
54
+ * ✅ 'public/assets/image-1.png'
55
+ *
56
+ * @description
57
+ * This method is designed for all files regardless of size, but especially for
58
+ * larger files that may not fit into memory (it intelligently determines the best approach on the fly)
59
+ * For files > 100 MB, it streams the data directly to disk instead of loading it all into memory
60
+ */
61
+ fetchRemoteWriteLocalLargeFiles<const I extends string, const O extends string>(inputUrl: I, outputPathI: O, useDetectedExtension?: boolean): Promise<void>;
62
+ }
63
+
64
+ export { FsFetch };
@@ -0,0 +1,19 @@
1
+ import {
2
+ FsFetch
3
+ } from "../chunk-Q2VF3BVH.js";
4
+ import "../chunk-TDMPLELZ.js";
5
+ import "../chunk-KDWGS5GC.js";
6
+ import "../chunk-FPB77OGJ.js";
7
+ import "../chunk-R63XI7FS.js";
8
+ import "../chunk-XCA34DKZ.js";
9
+ import "../chunk-7FHBNIB7.js";
10
+ import "../chunk-C2ANVZLG.js";
11
+ import "../chunk-KNLXF622.js";
12
+ import "../chunk-UW52DMHT.js";
13
+ import "../chunk-6HHKXBIM.js";
14
+ import "../chunk-Z2WZLZC4.js";
15
+ import "../chunk-7QVYU63E.js";
16
+ export {
17
+ FsFetch
18
+ };
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,30 @@
1
+ import { Unit, SizeOpts } from '../types/index.js';
2
+ import { FsAtomic } from '../fs-atomic/index.js';
3
+ import 'stream';
4
+ import 'buffer';
5
+ import '../fs-base/index.js';
6
+ import 'node:stream';
7
+ import 'stream/web';
8
+ import 'dotenv-expand';
9
+ import '../types/stream.js';
10
+ import '../image/index.js';
11
+ import '../mime/index.js';
12
+ import '../url/index.js';
13
+ import '../utils/index.js';
14
+ import '../ld/index.js';
15
+
16
+ declare class FsSize extends FsAtomic {
17
+ cwd: string;
18
+ constructor(cwd: string);
19
+ private units;
20
+ private u;
21
+ autoFileSizeRaw(size: number | bigint): {
22
+ value: number;
23
+ unit: "B" | "KB" | "MB" | "GB" | "TB" | "PB" | undefined;
24
+ };
25
+ getSize<const S extends Unit | Lowercase<Unit> | "auto">(size: number | bigint, target: S, opts?: SizeOpts): string | number;
26
+ fileSizeMb<const T extends string>(path: T): number;
27
+ fileSize<const T extends string, const S extends Unit | Lowercase<Unit> | "auto">(path: T, target: S, opts?: SizeOpts): string | number;
28
+ }
29
+
30
+ export { FsSize };
@@ -0,0 +1,16 @@
1
+ import {
2
+ FsSize
3
+ } from "../chunk-FPB77OGJ.js";
4
+ import "../chunk-R63XI7FS.js";
5
+ import "../chunk-XCA34DKZ.js";
6
+ import "../chunk-7FHBNIB7.js";
7
+ import "../chunk-C2ANVZLG.js";
8
+ import "../chunk-KNLXF622.js";
9
+ import "../chunk-UW52DMHT.js";
10
+ import "../chunk-6HHKXBIM.js";
11
+ import "../chunk-Z2WZLZC4.js";
12
+ import "../chunk-7QVYU63E.js";
13
+ export {
14
+ FsSize
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,194 @@
1
+ import { WriteStreamDataShape, WriteStreamOptions, WriteFileAsyncOptions, ReadDirOptions } from '../types/index.js';
2
+ import { FsCore } from '../fs-core/index.js';
3
+ import { Streamable } from '../types/stream.js';
4
+ import 'stream';
5
+ import 'buffer';
6
+ import '../fs-size/index.js';
7
+ import '../fs-atomic/index.js';
8
+ import '../fs-base/index.js';
9
+ import 'node:stream';
10
+ import 'stream/web';
11
+ import 'dotenv-expand';
12
+ import '../image/index.js';
13
+ import '../mime/index.js';
14
+ import '../url/index.js';
15
+ import '../utils/index.js';
16
+ import '../ld/index.js';
17
+
18
+ declare class FsTmp extends FsCore {
19
+ cwd: string;
20
+ constructor(cwd: string);
21
+ /**
22
+ * Write data to a file in the system's tmp directory
23
+ * @param filename The filename (can include subdirectories like "img-probe/file.txt")
24
+ * @param data The data to write
25
+ * @param options Optional write stream options
26
+ * @returns The full path to the written file
27
+ * @example
28
+ * ```ts
29
+ * const fs = new Fs(process.cwd());
30
+ * const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
31
+ * // Or with a subdirectory:
32
+ * fs.writeTmp("img-probe/output.png", imageBuffer);
33
+ * ```
34
+ */
35
+ writeTmp<const F extends string>(filename: F, data: WriteStreamDataShape, options?: WriteStreamOptions): void;
36
+ writeTmpAsync<const F extends string>(filename: F, data: string, options?: WriteFileAsyncOptions): Promise<string | void>;
37
+ readTmpAsync<const F extends string>(filename: F): Promise<Buffer<ArrayBufferLike>>;
38
+ /**
39
+ * Read a file from the tmp directory
40
+ * @param filename The filename to read (can include subdirectories)
41
+ * @returns Buffer containing the file data
42
+ * @example
43
+ * ```ts
44
+ * const fs = new Fs(process.cwd());
45
+ * const data = fs.readTmp("session-data.json");
46
+ * const parsed = JSON.parse(data.toString("utf-8"));
47
+ * ```
48
+ */
49
+ readTmp<const F extends string>(filename: F): Buffer<ArrayBuffer>;
50
+ /**
51
+ * Scan the tmp directory for files matching a pattern
52
+ * @param pattern Optional pattern to filter files (e.g., "img-probe")
53
+ * @param options Options for directory reading (defaults to non-recursive to avoid permission issues)
54
+ * @returns Array of matching file paths relative to tmp directory
55
+ * @example
56
+ * ```ts
57
+ * const fs = new Fs(process.cwd());
58
+ * // Get all img-probe files
59
+ * const imgFiles = fs.scanTmp("img-probe");
60
+ * // Get all files in tmp (non-recursive)
61
+ * const allFiles = fs.scanTmp();
62
+ * ```
63
+ */
64
+ scanTmp(pattern?: string | RegExp, options?: ReadDirOptions): string[];
65
+ /**
66
+ * Extract specific files from tmp directory to a target location
67
+ * @param pattern Pattern to match files (e.g., "img-probe")
68
+ * @param targetDir Target directory to extract files to
69
+ * @param options Options for extraction behavior
70
+ * @returns Array of extracted file paths
71
+ * @example
72
+ * ```ts
73
+ * const fs = new Fs(process.cwd());
74
+ * // Extract all img-probe files to ./output
75
+ * const extracted = fs.extractFromTmp("img-probe", "./output");
76
+ * // Extract with custom behavior
77
+ * fs.extractFromTmp("session-", "./sessions", {
78
+ * preserveStructure: true,
79
+ * cleanupAfter: true
80
+ * });
81
+ * ```
82
+ */
83
+ extractFromTmp(pattern: string, targetDir: string, options?: {
84
+ preserveStructure?: boolean;
85
+ cleanupAfter?: boolean;
86
+ overwrite?: boolean;
87
+ }): string[];
88
+ /**
89
+ * Clean up tmp files matching a pattern
90
+ * @param pattern Pattern to match files for deletion
91
+ * @param maxAge Optional max age in milliseconds (only delete files older than this)
92
+ * @returns Number of files removed
93
+ * @example
94
+ * ```ts
95
+ * const fs = new Fs(process.cwd());
96
+ * // Remove all img-probe files
97
+ * fs.cleanupTmp("img-probe");
98
+ * // Remove session files older than 1 hour
99
+ * fs.cleanupTmp("session-", 60 * 60 * 1000);
100
+ * ```
101
+ */
102
+ cleanupTmp(pattern: string, maxAge?: number): number;
103
+ /**
104
+ * Generate a unique tmp filename with optional prefix
105
+ * @param prefix Optional prefix for the filename
106
+ * @param extension Optional file extension (without dot)
107
+ * @returns Unique filename
108
+ * @example
109
+ * ```ts
110
+ * const fs = new Fs(process.cwd());
111
+ * const filename = fs.uniqueTmpName("img-probe", "png");
112
+ * // Returns: "img-probe-1701234567890-a3b2c1.png"
113
+ * ```
114
+ */
115
+ uniqueTmpName(prefix?: string, extension?: string): string;
116
+ /**
117
+ * Async generator for cleaning tmp files with batched removal
118
+ * @param pattern Pattern to match files for deletion
119
+ * @param batchSize Number of files to remove per batch (default 10)
120
+ * @yields Progress information during cleanup
121
+ * @returns Final cleanup summary
122
+ * @example
123
+ * ```ts
124
+ * const fs = new Fs(process.cwd());
125
+ * // Clean up with progress tracking
126
+ * for await (const progress of fs.cleanTmpGenerator("session-", 25)) {
127
+ * console.log(progress);
128
+ * }
129
+ * ```
130
+ */
131
+ cleanTmpGenerator(pattern: string | RegExp, batchSize?: number): AsyncGenerator<{
132
+ action: "removing";
133
+ batch: string[];
134
+ batchNumber: number;
135
+ totalBatches: number;
136
+ totalFound: number;
137
+ removed: number;
138
+ batchSize?: undefined;
139
+ totalRemoved?: undefined;
140
+ remaining?: undefined;
141
+ } | {
142
+ action: "batch-complete";
143
+ batchNumber: number;
144
+ batchSize: number;
145
+ totalRemoved: number;
146
+ remaining: number;
147
+ batch?: undefined;
148
+ totalBatches?: undefined;
149
+ totalFound?: undefined;
150
+ removed?: undefined;
151
+ }, {
152
+ action: "complete";
153
+ totalRemoved: number;
154
+ totalBatches: number;
155
+ pattern: string;
156
+ }, unknown>;
157
+ /**
158
+ * Async version of withWs with atomic write support and progress tracking
159
+ * @param path Target file path
160
+ * @param data Streamable data to write
161
+ * @param options Optional atomic write and abort signal
162
+ * @returns Promise with path and bytes written
163
+ * @example
164
+ * ```ts
165
+ * const fs = new Fs(process.cwd());
166
+ * // Simple async write
167
+ * const result = await fs.asyncWithWs("output.txt", "Hello World");
168
+ * console.log(`Wrote ${result.bytes} bytes to ${result.path}`);
169
+ *
170
+ * // Atomic write with temp file
171
+ * const { path, bytes } = await fs.asyncWithWs(
172
+ * "critical-data.json",
173
+ * JSON.stringify(data),
174
+ * { atomic: true }
175
+ * );
176
+ * ```
177
+ */
178
+ asyncWithWs(path: string, data: Streamable, options?: {
179
+ atomic?: boolean;
180
+ signal?: AbortSignal;
181
+ }): Promise<string | {
182
+ path: string;
183
+ bytes: number;
184
+ newPath?: undefined;
185
+ newBytes?: undefined;
186
+ } | {
187
+ path: string;
188
+ bytes: number;
189
+ newPath: string;
190
+ newBytes: number;
191
+ } | undefined>;
192
+ }
193
+
194
+ export { FsTmp };
@@ -0,0 +1,18 @@
1
+ import {
2
+ FsTmp
3
+ } from "../chunk-TDMPLELZ.js";
4
+ import "../chunk-KDWGS5GC.js";
5
+ import "../chunk-FPB77OGJ.js";
6
+ import "../chunk-R63XI7FS.js";
7
+ import "../chunk-XCA34DKZ.js";
8
+ import "../chunk-7FHBNIB7.js";
9
+ import "../chunk-C2ANVZLG.js";
10
+ import "../chunk-KNLXF622.js";
11
+ import "../chunk-UW52DMHT.js";
12
+ import "../chunk-6HHKXBIM.js";
13
+ import "../chunk-Z2WZLZC4.js";
14
+ import "../chunk-7QVYU63E.js";
15
+ export {
16
+ FsTmp
17
+ };
18
+ //# sourceMappingURL=index.js.map
@@ -1,16 +1,50 @@
1
+ import { ImageSpecs } from '../types/index.js';
1
2
  import { MimeService } from '../mime/index.js';
2
- import '../types/index.js';
3
+ import { Readable } from 'node:stream';
3
4
  import 'stream';
4
5
  import 'buffer';
5
6
  import '../url/index.js';
6
7
  import '../utils/index.js';
8
+ import '../ld/index.js';
7
9
 
8
10
  declare class ImageService extends MimeService {
11
+ cwd: string;
12
+ constructor(cwd: string);
13
+ /**
14
+ * Read exactly N bytes from a stream, returning a Buffer
15
+ * Closes stream after reading or on error
16
+ */
17
+ private readBytes;
18
+ /**
19
+ * Extract image metadata from a stream, reading only ~4KB for most formats
20
+ * Automatically handles PNG, JPEG, GIF, BMP, WebP, and AVIF
21
+ */
22
+ extractFromStream(stream: Readable, size?: number): Promise<ImageSpecs>;
23
+ /**
24
+ * Extract metadata from file path using streaming (memory efficient)
25
+ */
26
+ extractFromPath(filePath: string, size?: number): Promise<ImageSpecs>;
27
+ private isPNG;
28
+ private isJPEG;
29
+ private isGIF;
30
+ private isBMP;
31
+ private isWebP;
32
+ private isAVIF;
33
+ private extractPNGFromBuffer;
34
+ private extractJPEGFromBuffer;
35
+ private extractGIFFromBuffer;
36
+ private extractBMPFromBuffer;
37
+ private extractWebPFromBuffer;
38
+ private extractAVIFFromBuffer;
9
39
  private parseExif;
10
40
  private parseXmpFromAvif;
11
41
  private readVarSize;
12
42
  private findBox;
13
- getImageSpecsWorkup(buffer: Buffer<ArrayBufferLike>): {
43
+ /**
44
+ * Legacy method that processes entire buffer
45
+ * Use extractFromStream or extractFromPath for better memory efficiency
46
+ */
47
+ getImageSpecsWorkup(rawbuffer: Buffer<ArrayBufferLike>, size?: number): {
14
48
  width: number;
15
49
  height: number;
16
50
  format: "png";
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  ImageService
3
- } from "../chunk-KUGIFRTF.js";
4
- import "../chunk-GH6MFTV5.js";
5
- import "../chunk-6FJJLFJL.js";
6
- import "../chunk-O2P3L3CJ.js";
3
+ } from "../chunk-C2ANVZLG.js";
4
+ import "../chunk-KNLXF622.js";
5
+ import "../chunk-UW52DMHT.js";
6
+ import "../chunk-6HHKXBIM.js";
7
+ import "../chunk-Z2WZLZC4.js";
7
8
  import "../chunk-7QVYU63E.js";
8
9
  export {
9
10
  ImageService
package/dist/index.d.ts CHANGED
@@ -1,13 +1,20 @@
1
1
  export { default as Fs } from './fs/index.js';
2
+ export { FsAtomic } from './fs-atomic/index.js';
3
+ export { FsBase } from './fs-base/index.js';
4
+ export { FsCore } from './fs-core/index.js';
5
+ export { FsFetch } from './fs-fetch/index.js';
6
+ export { FsSize } from './fs-size/index.js';
7
+ export { FsTmp } from './fs-tmp/index.js';
2
8
  export { ImageService } from './image/index.js';
9
+ export { LevenshteinDistance } from './ld/index.js';
3
10
  export { AllMimeTypes, FileExtension, FileExtensionToMimeType, InferTopLevelPresent, MimeService, MimeTopLevelType, MimeType, MimeTypeToFileExtension, PresentMimeTopLevelTypes, extMimeMap, mimeToExt } from './mime/index.js';
4
- export { Abortable, ArrFieldReplacer, ArrayBufferView, ArrayOrReadOnlyArray, BashEnv, BoxInfo, BufferEncodingUnion, CTR, CoercionUnion, CommonExecOptions, CommonOptions, ConditionalPromise, ConditionalToRequired, DX, DeepPartial, DeepPartialFields, DeepReplace, Depth, Dict, Equal, ExcludeFieldEnumerable, ExecSyncOptions, ExecSyncOptionsWithBufferEncoding, ExecSyncOptionsWithStringEncoding, ExecuteCommandProps, Expect, Extends, FieldToConditionallyNever, IOType, ImageSpecs, InferDepth, InjectScriptsProps, IsExact, IsOptional, MkDirOptions, MkDirSyncOptions, MkDirSyncProps, Mode, ObjEncodingOptions, OmitSrc, OnlyOptional, OnlyRequired, OpenMode, ParsedUrlInfo, ProcessEnv, ProcessEnvOptions, RTC, ReadDirOptions, ReadDirOptionsEntity, ReadDirProps, RemoveFields, RequireNested, RequiredToConditional, Rm, RmDirOptions, RmDirProps, Signals, SizeOpts, StdioOptions, TCN, TypedArray, Unenumerate, Unit, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR, unitsObj } from './types/index.js';
11
+ export { Abortable, ArrFieldReplacer, ArrayBufferView, ArrayOrReadOnlyArray, BashEnv, BoxInfo, BufferEncodingUnion, CTR, CoercionUnion, CommonExecOptions, CommonOptions, ConditionalPromise, ConditionalToRequired, DX, DeepPartial, DeepPartialFields, DeepReplace, Depth, Dict, Equal, ExcludeFieldEnumerable, ExecSyncOptions, ExecSyncOptionsWithBufferEncoding, ExecSyncOptionsWithStringEncoding, ExecuteCommandProps, Expect, Extends, FieldToConditionallyNever, IOType, ImageSpecs, InferDepth, InjectScriptsProps, IsExact, IsOptional, MkDirOptions, MkDirSyncOptions, MkDirSyncProps, Mode, NoParamCallback, ObjEncodingOptions, OmitSrc, OnlyOptional, OnlyRequired, OpenMode, ParsedUrlInfo, ProcessEnv, ProcessEnvOptions, RTC, ReadDirOptions, ReadDirOptionsEntity, ReadDirProps, RemoveFields, RequireNested, RequiredToConditional, Rm, RmOptions, Signals, SizeOpts, StdioOptions, TCN, TypedArray, Unenumerate, Unit, UnwrapPromise, Without, WriteFileAsyncDataUnion, WriteFileAsyncOptions, WriteFileAsyncProps, WriteStreamDataShape, WriteStreamOptions, WriteStreamProps, XOR, unitsObj } from './types/index.js';
5
12
  export { AsyncIter, Bin, Streamable, WebRS } from './types/stream.js';
6
13
  export { HandleQueryParamsOrHash, InferExtensionIfPresent, LastSegment, SplitForwardSlash, UrlFileExt, UrlService } from './url/index.js';
7
14
  export { UtilsService } from './utils/index.js';
8
- import 'node:stream';
9
- import 'stream/web';
10
- import 'dotenv-expand';
11
15
  import 'sharp';
12
16
  import 'stream';
13
17
  import 'buffer';
18
+ import 'node:stream';
19
+ import 'stream/web';
20
+ import 'dotenv-expand';