@d0paminedriven/fs 10.1.0 → 12.0.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/dist/docs/index.d.ts +151 -0
  2. package/dist/docs/index.js +1163 -0
  3. package/dist/extract/client.d.ts +56 -0
  4. package/dist/extract/client.js +116 -0
  5. package/dist/extract/index.d.ts +66 -0
  6. package/dist/extract/index.js +620 -0
  7. package/dist/fs/index.d.ts +18 -58
  8. package/dist/fs/index.js +89 -19
  9. package/dist/fs-atomic/index.d.ts +25 -39
  10. package/dist/fs-atomic/index.js +94 -13
  11. package/dist/fs-base/index.d.ts +105 -113
  12. package/dist/fs-base/index.js +197 -12
  13. package/dist/fs-core/index.d.ts +18 -26
  14. package/dist/fs-core/index.js +43 -16
  15. package/dist/fs-fetch/index.d.ts +48 -65
  16. package/dist/fs-fetch/index.js +183 -18
  17. package/dist/fs-size/index.d.ts +15 -31
  18. package/dist/fs-size/index.js +63 -15
  19. package/dist/fs-tmp/index.d.ts +178 -195
  20. package/dist/fs-tmp/index.js +320 -17
  21. package/dist/images/index.d.ts +443 -0
  22. package/dist/images/index.js +893 -0
  23. package/dist/images/workup.d.ts +26 -0
  24. package/dist/images/workup.js +316 -0
  25. package/dist/index.d.ts +48 -22
  26. package/dist/index.js +19 -64
  27. package/dist/ld/index.d.ts +14 -16
  28. package/dist/ld/index.js +54 -6
  29. package/dist/mime/index.d.ts +301 -296
  30. package/dist/mime/index.js +348 -13
  31. package/dist/mixins/index.d.ts +30 -0
  32. package/dist/mixins/index.js +54 -0
  33. package/dist/types/index.d.ts +339 -260
  34. package/dist/types/index.js +10 -6
  35. package/dist/types/stream.d.ts +7 -9
  36. package/dist/types/stream.js +1 -1
  37. package/dist/url/index.d.ts +18 -25
  38. package/dist/url/index.js +19 -8
  39. package/dist/utils/index.d.ts +18 -26
  40. package/dist/utils/index.js +80 -7
  41. package/package.json +42 -22
  42. package/dist/chunk-4D2YBCI6.js +0 -163
  43. package/dist/chunk-5CACVZVF.js +0 -386
  44. package/dist/chunk-5H6GE5AO.js +0 -14
  45. package/dist/chunk-7QVYU63E.js +0 -7
  46. package/dist/chunk-DNR5ZI2T.js +0 -75
  47. package/dist/chunk-JZ6JNZZ6.js +0 -77
  48. package/dist/chunk-L2QMQOEJ.js +0 -366
  49. package/dist/chunk-NJHN5OE3.js +0 -33
  50. package/dist/chunk-OHKRQJZH.js +0 -82
  51. package/dist/chunk-OT5JEQKW.js +0 -139
  52. package/dist/chunk-PATMSIQK.js +0 -367
  53. package/dist/chunk-PB5A7ZFD.js +0 -79
  54. package/dist/chunk-VDKUXJE7.js +0 -240
  55. package/dist/chunk-Y5QWE4EG.js +0 -1335
  56. package/dist/chunk-YRCJWFZD.js +0 -107
  57. package/dist/image/index.d.ts +0 -182
  58. package/dist/image/index.js +0 -13
  59. package/dist/image/workup.d.ts +0 -40
  60. package/dist/image/workup.js +0 -12
@@ -1,386 +0,0 @@
1
- import {
2
- MimeService
3
- } from "./chunk-L2QMQOEJ.js";
4
- import {
5
- __name
6
- } from "./chunk-7QVYU63E.js";
7
-
8
- // src/image/workup.ts
9
- var ImageServiceWorkup = class extends MimeService {
10
- constructor(cwd) {
11
- super();
12
- this.cwd = cwd;
13
- }
14
- static {
15
- __name(this, "ImageServiceWorkup");
16
- }
17
- /**
18
- * Read exactly N bytes from a stream, returning a Buffer
19
- * Closes stream after reading or on error
20
- */
21
- async readBytes(stream, bytes) {
22
- return new Promise((resolve, reject) => {
23
- const chunks = Array.of();
24
- let totalBytes = 0;
25
- const cleanup = /* @__PURE__ */ __name(() => {
26
- stream.removeAllListeners();
27
- stream.destroy();
28
- }, "cleanup");
29
- stream.on("error", (err) => {
30
- cleanup();
31
- reject(err);
32
- });
33
- stream.on("data", (chunk) => {
34
- const remaining = bytes - totalBytes;
35
- if (chunk.length <= remaining) {
36
- chunks.push(chunk);
37
- totalBytes += chunk.length;
38
- } else {
39
- chunks.push(chunk.subarray(0, remaining));
40
- totalBytes = bytes;
41
- }
42
- if (totalBytes >= bytes) {
43
- cleanup();
44
- resolve(Buffer.concat(chunks));
45
- }
46
- });
47
- stream.on("end", () => {
48
- cleanup();
49
- resolve(Buffer.concat(chunks));
50
- });
51
- });
52
- }
53
- parseExif(buffer, app1Pos, app1Size) {
54
- const segmentStart = app1Pos + 4;
55
- const segmentEnd = app1Pos + 2 + app1Size;
56
- if (segmentEnd - segmentStart < 16 || segmentEnd > buffer.length) {
57
- return { orientation: null, dateTimeOriginal: null };
58
- }
59
- const headerEnd = Math.min(segmentStart + 6, segmentEnd, buffer.length);
60
- if (headerEnd - segmentStart < 6) {
61
- return { orientation: null, dateTimeOriginal: null };
62
- }
63
- const exifHeader = buffer.toString("ascii", segmentStart, headerEnd);
64
- if (exifHeader !== "Exif\0\0") {
65
- return { orientation: null, dateTimeOriginal: null };
66
- }
67
- const tiffStart = segmentStart + 6;
68
- const tiffEnd = segmentEnd;
69
- if (tiffEnd - tiffStart < 8) {
70
- return { orientation: null, dateTimeOriginal: null };
71
- }
72
- const byteOrder = buffer.toString("ascii", tiffStart, tiffStart + 2);
73
- const littleEndian = byteOrder === "II";
74
- const bigEndian = byteOrder === "MM";
75
- if (!littleEndian && !bigEndian) {
76
- return { orientation: null, dateTimeOriginal: null };
77
- }
78
- const readUInt16 = /* @__PURE__ */ __name((pos) => {
79
- if (pos < 0 || pos + 2 > tiffEnd || pos + 2 > buffer.length) return null;
80
- return littleEndian ? buffer.readUInt16LE(pos) : buffer.readUInt16BE(pos);
81
- }, "readUInt16");
82
- const readUInt32 = /* @__PURE__ */ __name((pos) => {
83
- if (pos < 0 || pos + 4 > tiffEnd || pos + 4 > buffer.length) return null;
84
- return littleEndian ? buffer.readUInt32LE(pos) : buffer.readUInt32BE(pos);
85
- }, "readUInt32");
86
- const magic = readUInt16(tiffStart + 2);
87
- if (magic !== 42) {
88
- return { orientation: null, dateTimeOriginal: null };
89
- }
90
- const ifd0Offset = readUInt32(tiffStart + 4);
91
- if (ifd0Offset === null || ifd0Offset < 8) {
92
- return { orientation: null, dateTimeOriginal: null };
93
- }
94
- const ifd0Pos = tiffStart + ifd0Offset;
95
- if (ifd0Pos + 2 > tiffEnd) {
96
- return { orientation: null, dateTimeOriginal: null };
97
- }
98
- const numEntries = readUInt16(ifd0Pos);
99
- if (numEntries === null || numEntries === 0 || numEntries > 500) {
100
- return { orientation: null, dateTimeOriginal: null };
101
- }
102
- let orientation = null;
103
- let dateTimeOriginal = null;
104
- const ifdDataStart = ifd0Pos + 2;
105
- const ifdDataEnd = ifdDataStart + numEntries * 12;
106
- if (ifdDataEnd > tiffEnd) {
107
- const maxEntries = Math.floor((tiffEnd - ifdDataStart) / 12);
108
- if (maxEntries <= 0) {
109
- return { orientation, dateTimeOriginal };
110
- }
111
- for (let i = 0; i < maxEntries; i++) {
112
- const entryPos = ifdDataStart + i * 12;
113
- const tag = readUInt16(entryPos);
114
- const type = readUInt16(entryPos + 2);
115
- const count = readUInt32(entryPos + 4);
116
- if (tag === null || type === null || count === null) continue;
117
- if (tag === 274 && type === 3 && count === 1) {
118
- orientation = readUInt16(entryPos + 8);
119
- if (orientation && (orientation < 1 || orientation > 8)) {
120
- orientation = null;
121
- }
122
- }
123
- if (tag === 36867 && type === 2 && count === 20) {
124
- const offset = readUInt32(entryPos + 8);
125
- if (offset !== null) {
126
- const stringPos = tiffStart + offset;
127
- const stringEnd = stringPos + 19;
128
- if (stringEnd <= tiffEnd && stringEnd <= buffer.length) {
129
- try {
130
- dateTimeOriginal = buffer.toString(
131
- "ascii",
132
- stringPos,
133
- stringEnd
134
- );
135
- if (!/^\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}/.test(dateTimeOriginal)) {
136
- dateTimeOriginal = null;
137
- }
138
- } catch {
139
- dateTimeOriginal = null;
140
- }
141
- }
142
- }
143
- }
144
- }
145
- } else {
146
- for (let i = 0; i < numEntries; i++) {
147
- const entryPos = ifdDataStart + i * 12;
148
- const tag = readUInt16(entryPos);
149
- const type = readUInt16(entryPos + 2);
150
- const count = readUInt32(entryPos + 4);
151
- if (tag === null || type === null || count === null) continue;
152
- if (tag === 274 && type === 3 && count === 1) {
153
- orientation = readUInt16(entryPos + 8);
154
- if (orientation && (orientation < 1 || orientation > 8)) {
155
- orientation = null;
156
- }
157
- } else if (tag === 36867 && type === 2 && count === 20) {
158
- const offset = readUInt32(entryPos + 8);
159
- if (offset !== null) {
160
- const stringPos = tiffStart + offset;
161
- const stringEnd = stringPos + 19;
162
- if (stringEnd <= tiffEnd && stringEnd <= buffer.length) {
163
- try {
164
- const extracted = buffer.toString(
165
- "ascii",
166
- stringPos,
167
- stringEnd
168
- );
169
- if (/^\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}/.test(extracted)) {
170
- dateTimeOriginal = extracted;
171
- }
172
- } catch {
173
- console.warn("invalid ascii data");
174
- }
175
- }
176
- }
177
- }
178
- }
179
- }
180
- return { orientation, dateTimeOriginal };
181
- }
182
- parseXmpFromAvif(buffer, meta, _ipco) {
183
- const iinf = this.findBox(
184
- buffer,
185
- "iinf",
186
- meta.pos + 4,
187
- meta.pos + meta.size
188
- );
189
- if (!iinf) return null;
190
- let pos = iinf.pos;
191
- const version = buffer[pos++];
192
- const itemCount = version === 0 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
193
- pos += version === 0 ? 2 : 4;
194
- let xmpItemId;
195
- for (let i = 0; i < itemCount; i++) {
196
- const infeStart = pos;
197
- const infeSize = buffer.readUInt32BE(pos);
198
- if (buffer.toString("ascii", pos + 4, pos + 8) !== "infe") break;
199
- pos += 8;
200
- const infeVersion = buffer?.[pos++];
201
- if (!infeVersion) return null;
202
- const itemId = infeVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
203
- pos += infeVersion < 2 ? 2 : 4;
204
- pos += 2;
205
- const itemType = buffer.toString("ascii", pos, pos + 4);
206
- pos += 4;
207
- let nameEnd = pos;
208
- while (buffer[nameEnd] !== 0 && nameEnd < infeStart + infeSize) nameEnd++;
209
- pos = nameEnd + 1;
210
- if (itemType === "mime") {
211
- let ctEnd = pos;
212
- while (buffer[ctEnd] !== 0 && ctEnd < infeStart + infeSize) ctEnd++;
213
- const contentType = buffer.toString("ascii", pos, ctEnd);
214
- if (contentType === "application/rdf+xml") {
215
- xmpItemId = itemId;
216
- break;
217
- }
218
- pos = ctEnd + 1;
219
- }
220
- pos = infeStart + infeSize;
221
- }
222
- if (!xmpItemId) return null;
223
- const iloc = this.findBox(
224
- buffer,
225
- "iloc",
226
- meta.pos + 4,
227
- meta.pos + meta.size
228
- );
229
- if (!iloc) return null;
230
- pos = iloc.pos;
231
- const ilocVersion = buffer[pos++];
232
- const sizes = buffer?.[pos++];
233
- if (!sizes) return null;
234
- const offsetSize = sizes >> 4 & 15;
235
- const lengthSize = sizes & 15;
236
- let indexSize = 0;
237
- if (ilocVersion === 1 || ilocVersion === 2) {
238
- const indexSizes = buffer?.[pos++];
239
- if (!indexSizes) return null;
240
- indexSize = indexSizes >> 4 & 15;
241
- }
242
- if (!ilocVersion) return null;
243
- const buffpos = buffer?.[pos++];
244
- if (!buffpos) return null;
245
- const baseOffsetSize = ilocVersion < 2 ? 0 : buffpos >> 4 & 15;
246
- const itemCountIloc = ilocVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
247
- pos += ilocVersion < 2 ? 2 : 4;
248
- let xmpOffset = 0;
249
- let xmpLength = 0;
250
- for (let i = 0; i < itemCountIloc; i++) {
251
- const curItemId = ilocVersion < 2 ? buffer.readUInt16BE(pos) : buffer.readUInt32BE(pos);
252
- pos += ilocVersion < 2 ? 2 : 4;
253
- if (curItemId !== xmpItemId) {
254
- if (ilocVersion === 1 || ilocVersion === 2) pos += 2;
255
- pos += 2;
256
- pos += baseOffsetSize;
257
- const extentCount2 = buffer.readUInt16BE(pos);
258
- pos += 2;
259
- for (let e = 0; e < extentCount2; e++) {
260
- if (indexSize > 0) pos += indexSize;
261
- pos += offsetSize + lengthSize;
262
- }
263
- continue;
264
- }
265
- if (ilocVersion === 1 || ilocVersion === 2) {
266
- const constructionMethod = buffer.readUInt16BE(pos);
267
- pos += 2;
268
- if (constructionMethod !== 0) return null;
269
- }
270
- pos += 2;
271
- const baseOffset = this.readVarSize(buffer, pos, baseOffsetSize);
272
- pos += baseOffsetSize;
273
- const extentCount = buffer.readUInt16BE(pos);
274
- pos += 2;
275
- if (extentCount !== 1) return null;
276
- if (indexSize > 0) pos += indexSize;
277
- const extentOffset = this.readVarSize(buffer, pos, offsetSize);
278
- pos += offsetSize;
279
- const extentLength = this.readVarSize(buffer, pos, lengthSize);
280
- xmpOffset = baseOffset + extentOffset;
281
- xmpLength = extentLength;
282
- break;
283
- }
284
- if (xmpOffset === 0 || xmpLength === 0 || xmpOffset + xmpLength > buffer.length)
285
- return null;
286
- return buffer.toString("utf8", xmpOffset, xmpOffset + xmpLength);
287
- }
288
- readVarSize(buffer, pos, size) {
289
- if (size === 0) return 0;
290
- if (size === 1 && buffer?.[pos]) return buffer?.[pos];
291
- if (size === 2) return buffer.readUInt16BE(pos);
292
- if (size === 3) {
293
- const pos1 = buffer?.[pos + 1], pos2 = buffer?.[pos + 2];
294
- if (buffer?.[pos] && pos1 && pos2) {
295
- return buffer[pos] << 16 | pos1 << 8 | pos2;
296
- }
297
- throw new Error("Invalid var size");
298
- }
299
- if (size === 4) return buffer.readUInt32BE(pos);
300
- if (size === 8) return Number(buffer.readBigUInt64BE(pos));
301
- throw new Error("Invalid var size");
302
- }
303
- findBox(buffer, type, start = 0, end = buffer.length) {
304
- let pos = start;
305
- while (pos < end) {
306
- let boxSize = buffer.readUInt32BE(pos);
307
- const boxType = buffer.toString("ascii", pos + 4, pos + 8);
308
- let hdrSize = 8;
309
- if (boxSize === 1) {
310
- boxSize = Number(buffer.readBigUInt64BE(pos + 8));
311
- hdrSize = 16;
312
- } else if (boxSize === 0) {
313
- boxSize = end - pos;
314
- }
315
- if (boxType === type) {
316
- return { pos: pos + hdrSize, size: boxSize - hdrSize };
317
- }
318
- pos += boxSize;
319
- }
320
- return null;
321
- }
322
- mapChrmToColorSpace(chrm, fallback) {
323
- const tol = 100;
324
- if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 64e3) < tol && Math.abs(chrm.red_y - 33e3) < tol && Math.abs(chrm.green_x - 3e4) < tol && Math.abs(chrm.green_y - 6e4) < tol && Math.abs(chrm.blue_x - 15e3) < tol && Math.abs(chrm.blue_y - 6e3) < tol)
325
- return "srgb";
326
- if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 64e3) < tol && Math.abs(chrm.red_y - 33e3) < tol && Math.abs(chrm.green_x - 21e3) < tol && Math.abs(chrm.green_y - 71e3) < tol && Math.abs(chrm.blue_x - 15e3) < tol && Math.abs(chrm.blue_y - 6e3) < tol)
327
- return "adobe_rgb";
328
- if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 68e3) < tol && Math.abs(chrm.red_y - 32e3) < tol && Math.abs(chrm.green_x - 26500) < tol && Math.abs(chrm.green_y - 69e3) < tol && Math.abs(chrm.blue_x - 15e3) < tol && Math.abs(chrm.blue_y - 6e3) < tol)
329
- return "display_p3";
330
- if (Math.abs(chrm.white_x - 34590) < tol && Math.abs(chrm.white_y - 35850) < tol && // D50 white point
331
- Math.abs(chrm.red_x - 73470) < tol && Math.abs(chrm.red_y - 26530) < tol && Math.abs(chrm.green_x - 15960) < tol && Math.abs(chrm.green_y - 85040) < tol && Math.abs(chrm.blue_x - 3600) < tol && Math.abs(chrm.blue_y - 1e3) < tol)
332
- return "prophoto_rgb";
333
- if (Math.abs(chrm.white_x - 31270) < tol && Math.abs(chrm.white_y - 32900) < tol && Math.abs(chrm.red_x - 70800) < tol && Math.abs(chrm.red_y - 29200) < tol && Math.abs(chrm.green_x - 17e3) < tol && Math.abs(chrm.green_y - 79700) < tol && Math.abs(chrm.blue_x - 13100) < tol && Math.abs(chrm.blue_y - 4600) < tol)
334
- return "rec2020";
335
- return fallback;
336
- }
337
- xmpToColorSpaceWorkup(space, target) {
338
- return `<photoshop:${target}>${space}</photoshop:${target}>`;
339
- }
340
- mapXmpToColorSpace(xmpText, fallback) {
341
- const lower = xmpText.toLowerCase();
342
- if (lower.includes(this.xmpToColorSpaceWorkup("srgb", "iccprofile")))
343
- return "srgb";
344
- if (lower.includes(
345
- this.xmpToColorSpaceWorkup("adobe rgb (1998)", "iccprofile")
346
- ))
347
- return "adobe_rgb";
348
- if (lower.includes(this.xmpToColorSpaceWorkup("display p3", "iccprofile")))
349
- return "display_p3";
350
- if (lower.includes(this.xmpToColorSpaceWorkup("prophoto rgb", "iccprofile")))
351
- return "prophoto_rgb";
352
- if (lower.includes(this.xmpToColorSpaceWorkup("rgb", "colormode")) && lower.includes("adobe rgb"))
353
- return "adobe_rgb";
354
- if (lower.includes(this.xmpToColorSpaceWorkup("grayscale", "colormode")))
355
- return "gray";
356
- return fallback;
357
- }
358
- mapProfileToColorSpace(profileName, fallback) {
359
- if (!profileName || profileName === "embedded" || profileName.toLowerCase().includes("icc profile"))
360
- return fallback;
361
- const lower = profileName.toLowerCase();
362
- if (lower.includes("srgb") || lower.includes("iec61966") || lower.includes("srgb2014"))
363
- return "srgb";
364
- if (lower.includes("display p3") || lower.includes("display-p3") || lower.includes("dci-p3") || lower.includes("p3"))
365
- return "display_p3";
366
- if (lower.includes("adobe rgb") || lower.includes("adobergb") || lower.includes("adobe rgb (1998)"))
367
- return "adobe_rgb";
368
- if (lower.includes("prophoto rgb") || lower.includes("prophoto") || lower.includes("romm rgb") || lower.includes("romm") || lower.includes("iso 22028"))
369
- return "prophoto_rgb";
370
- if (lower.includes("rec2020") || lower.includes("bt.2020") || lower.includes("bt2020") || lower.includes("bt.2100") || lower.includes("itur_2100"))
371
- return "rec2020";
372
- if (lower.includes("rec709") || lower.includes("bt.709") || lower.includes("bt709"))
373
- return "rec709";
374
- if (lower.includes("cmyk")) return "cmyk";
375
- if (lower.includes("lab")) return "lab";
376
- if (lower.includes("xyz")) return "xyz";
377
- if (lower.includes("gray") || lower.includes("grey") || lower.includes("monochrome") || lower.includes("gamma") || lower.includes("gamma 2.2") || lower.includes("dot gain"))
378
- return "gray";
379
- return fallback;
380
- }
381
- };
382
-
383
- export {
384
- ImageServiceWorkup
385
- };
386
- //# sourceMappingURL=chunk-5CACVZVF.js.map
@@ -1,14 +0,0 @@
1
- // src/types/index.ts
2
- var unitsObj = {
3
- PB: 5,
4
- TB: 4,
5
- GB: 3,
6
- MB: 2,
7
- KB: 1,
8
- B: 0
9
- };
10
-
11
- export {
12
- unitsObj
13
- };
14
- //# sourceMappingURL=chunk-5H6GE5AO.js.map
@@ -1,7 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- export {
5
- __name
6
- };
7
- //# sourceMappingURL=chunk-7QVYU63E.js.map
@@ -1,75 +0,0 @@
1
- import {
2
- unitsObj
3
- } from "./chunk-5H6GE5AO.js";
4
- import {
5
- FsAtomic
6
- } from "./chunk-YRCJWFZD.js";
7
- import {
8
- __name
9
- } from "./chunk-7QVYU63E.js";
10
-
11
- // src/fs-size/index.ts
12
- import { statSync } from "fs";
13
- import { relative } from "path";
14
- var FsSize = class extends FsAtomic {
15
- constructor(cwd) {
16
- super(cwd ??= process.cwd());
17
- this.cwd = cwd;
18
- }
19
- static {
20
- __name(this, "FsSize");
21
- }
22
- units = unitsObj;
23
- u = ["B", "KB", "MB", "GB", "TB", "PB"];
24
- autoFileSizeRaw(size) {
25
- let s = typeof size === "bigint" ? Number(size) : size;
26
- let i = 0;
27
- while (s >= 1024 && i < this.u.length - 1) {
28
- s /= 1024;
29
- i++;
30
- }
31
- return { value: s, unit: this.u[i] };
32
- }
33
- getSize(size, target, opts = { decimals: 4, includeUnits: true }) {
34
- const { decimals, includeUnits } = opts;
35
- if (target === "auto") {
36
- const { value, unit } = this.autoFileSizeRaw(size);
37
- const rounded2 = value.toFixed(decimals);
38
- return includeUnits ? `${rounded2} ${unit}` : Number.parseFloat(rounded2);
39
- }
40
- const key = target.toUpperCase();
41
- const exp = this.units[key];
42
- const divisor = typeof size === "bigint" ? 1024n ** BigInt(exp) : 1024 ** exp;
43
- let v = 0;
44
- if (typeof size === "bigint" || typeof divisor === "bigint") {
45
- if (typeof size === "bigint" && typeof divisor === "bigint")
46
- v = Number(size / divisor);
47
- else if (typeof size !== "bigint" && typeof divisor === "bigint")
48
- v = size / Number(divisor);
49
- else if (typeof size === "bigint" && typeof divisor !== "bigint")
50
- v = Number(size) / divisor;
51
- } else if (typeof size === "number" && typeof divisor === "number") {
52
- v = size / divisor;
53
- }
54
- const rounded = v.toFixed(decimals);
55
- return includeUnits ? `${rounded} ${key}` : Number.parseFloat(rounded);
56
- }
57
- fileSizeMb(path) {
58
- return statSync(relative(this.cwd, path)).size / (1024 * 1024);
59
- }
60
- fileSize(path, target, opts) {
61
- if (!this.exists(path)) throw new Error(`path ${path} does not exist`);
62
- else {
63
- return this.getSize(
64
- statSync(relative(this.cwd, path)).size,
65
- target,
66
- opts
67
- );
68
- }
69
- }
70
- };
71
-
72
- export {
73
- FsSize
74
- };
75
- //# sourceMappingURL=chunk-DNR5ZI2T.js.map
@@ -1,77 +0,0 @@
1
- import {
2
- FsFetch
3
- } from "./chunk-4D2YBCI6.js";
4
- import {
5
- __name
6
- } from "./chunk-7QVYU63E.js";
7
-
8
- // src/fs/index.ts
9
- import { resolve } from "path";
10
- import sharp from "sharp";
11
- var Fs = class extends FsFetch {
12
- constructor(cwd) {
13
- super(cwd ??= process.cwd());
14
- this.cwd = cwd;
15
- cwd ??= process.cwd();
16
- }
17
- static {
18
- __name(this, "Fs");
19
- }
20
- async getImageSpecs(filePath, size = 4096 * 36) {
21
- if (filePath.startsWith("https")) {
22
- return await this.extractRemoteFs(filePath, size);
23
- }
24
- return await this.extractViaPath(filePath, size);
25
- }
26
- async getImageSpecsFlexi(target, size = 4096 * 36) {
27
- if (Buffer.isBuffer(target)) {
28
- return this.getImageSpecsWorkupFs(target, size);
29
- } else {
30
- return await this.getImageSpecs(target, size);
31
- }
32
- }
33
- async getImageSpecsTmp(filepath, size = 4096 * 36) {
34
- return this.extractViaPath(resolve(this.tmpDir, filepath), size);
35
- }
36
- /**
37
- * Extract image metadata using streaming (only reads ~4KB)
38
- * Much more memory efficient for large images
39
- */
40
- async getImageSpecsStream(filePath, size = 4096 * 36) {
41
- return this.extractFromPath(filePath, size);
42
- }
43
- async getImageSpecsStreamTmp(filePath) {
44
- return this.extractFromPath(resolve(this.tmpDir, filePath));
45
- }
46
- /**
47
- *
48
- * @access package-private
49
- *
50
- * work in progress, for internal package maintainer use only
51
- */
52
- // USE fluent-ffmpeg for video/animated image transforms (apng, etc)
53
- // https://www.npmjs.com/package/fluent-ffmpeg
54
- // https://www.npmjs.com/package/@types/fluent-ffmpeg
55
- async imageTransform({
56
- format,
57
- target,
58
- quality = 80,
59
- tint,
60
- resize
61
- }) {
62
- if (tint && !resize) {
63
- return await sharp(target).toFormat(format, { quality }).tint(tint).toBuffer();
64
- } else if (!tint && resize) {
65
- return await sharp(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
66
- } else if (tint && resize) {
67
- return await sharp(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
68
- } else {
69
- return await sharp(target).toFormat(format, { quality }).toBuffer();
70
- }
71
- }
72
- };
73
-
74
- export {
75
- Fs
76
- };
77
- //# sourceMappingURL=chunk-JZ6JNZZ6.js.map