@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.
- package/README.md +127 -51
- package/dist/{chunk-O2P3L3CJ.js → chunk-6HHKXBIM.js} +5 -2
- package/dist/chunk-7FHBNIB7.js +240 -0
- package/dist/{chunk-KUGIFRTF.js → chunk-C2ANVZLG.js} +345 -4
- package/dist/chunk-FPB77OGJ.js +75 -0
- package/dist/chunk-IU4MDHYM.js +75 -0
- package/dist/chunk-KDWGS5GC.js +69 -0
- package/dist/{chunk-GH6MFTV5.js → chunk-KNLXF622.js} +2 -2
- package/dist/chunk-Q2VF3BVH.js +165 -0
- package/dist/{chunk-MRKO3PAA.js → chunk-R63XI7FS.js} +1 -1
- package/dist/chunk-TDMPLELZ.js +367 -0
- package/dist/{chunk-6FJJLFJL.js → chunk-UW52DMHT.js} +2 -2
- package/dist/chunk-XCA34DKZ.js +107 -0
- package/dist/chunk-Z2WZLZC4.js +75 -0
- package/dist/fs/index.d.ts +21 -476
- package/dist/fs/index.js +13 -6
- package/dist/fs-atomic/index.d.ts +38 -0
- package/dist/fs-atomic/index.js +14 -0
- package/dist/fs-base/index.d.ts +112 -0
- package/dist/fs-base/index.js +13 -0
- package/dist/fs-core/index.d.ts +24 -0
- package/dist/fs-core/index.js +17 -0
- package/dist/fs-fetch/index.d.ts +64 -0
- package/dist/fs-fetch/index.js +19 -0
- package/dist/fs-size/index.d.ts +30 -0
- package/dist/fs-size/index.js +16 -0
- package/dist/fs-tmp/index.d.ts +194 -0
- package/dist/fs-tmp/index.js +18 -0
- package/dist/image/index.d.ts +36 -2
- package/dist/image/index.js +5 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +36 -8
- package/dist/ld/index.d.ts +14 -0
- package/dist/ld/index.js +8 -0
- package/dist/mime/index.d.ts +5 -4
- package/dist/mime/index.js +4 -3
- package/dist/types/index.d.ts +13 -13
- package/dist/types/index.js +1 -1
- package/dist/types/stream.d.ts +2 -1
- package/dist/url/index.d.ts +1 -0
- package/dist/url/index.js +3 -2
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +2 -1
- package/package.json +32 -4
- package/dist/chunk-SYISQ57E.js +0 -895
|
@@ -1,15 +1,348 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MimeService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KNLXF622.js";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
6
|
} from "./chunk-7QVYU63E.js";
|
|
7
7
|
|
|
8
8
|
// src/image/index.ts
|
|
9
|
+
import { createReadStream } from "fs";
|
|
10
|
+
import { relative } from "path";
|
|
9
11
|
var ImageService = class extends MimeService {
|
|
12
|
+
constructor(cwd) {
|
|
13
|
+
super();
|
|
14
|
+
this.cwd = cwd;
|
|
15
|
+
}
|
|
10
16
|
static {
|
|
11
17
|
__name(this, "ImageService");
|
|
12
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Read exactly N bytes from a stream, returning a Buffer
|
|
21
|
+
* Closes stream after reading or on error
|
|
22
|
+
*/
|
|
23
|
+
async readBytes(stream, bytes) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const chunks = [];
|
|
26
|
+
let totalBytes = 0;
|
|
27
|
+
const cleanup = /* @__PURE__ */ __name(() => {
|
|
28
|
+
stream.removeAllListeners();
|
|
29
|
+
stream.destroy();
|
|
30
|
+
}, "cleanup");
|
|
31
|
+
stream.on("error", (err) => {
|
|
32
|
+
cleanup();
|
|
33
|
+
reject(err);
|
|
34
|
+
});
|
|
35
|
+
stream.on("data", (chunk) => {
|
|
36
|
+
const remaining = bytes - totalBytes;
|
|
37
|
+
if (chunk.length <= remaining) {
|
|
38
|
+
chunks.push(chunk);
|
|
39
|
+
totalBytes += chunk.length;
|
|
40
|
+
} else {
|
|
41
|
+
chunks.push(chunk.subarray(0, remaining));
|
|
42
|
+
totalBytes = bytes;
|
|
43
|
+
}
|
|
44
|
+
if (totalBytes >= bytes) {
|
|
45
|
+
cleanup();
|
|
46
|
+
resolve(Buffer.concat(chunks));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
stream.on("end", () => {
|
|
50
|
+
cleanup();
|
|
51
|
+
resolve(Buffer.concat(chunks));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Extract image metadata from a stream, reading only ~4KB for most formats
|
|
57
|
+
* Automatically handles PNG, JPEG, GIF, BMP, WebP, and AVIF
|
|
58
|
+
*/
|
|
59
|
+
async extractFromStream(stream, size = 4096) {
|
|
60
|
+
const headerSize = size;
|
|
61
|
+
const header = await this.readBytes(stream, headerSize);
|
|
62
|
+
if (this.isPNG(header)) {
|
|
63
|
+
return this.extractPNGFromBuffer(header);
|
|
64
|
+
}
|
|
65
|
+
if (this.isJPEG(header)) {
|
|
66
|
+
return this.extractJPEGFromBuffer(header);
|
|
67
|
+
}
|
|
68
|
+
if (this.isGIF(header)) {
|
|
69
|
+
return this.extractGIFFromBuffer(header);
|
|
70
|
+
}
|
|
71
|
+
if (this.isBMP(header)) {
|
|
72
|
+
return this.extractBMPFromBuffer(header);
|
|
73
|
+
}
|
|
74
|
+
if (this.isWebP(header)) {
|
|
75
|
+
return this.extractWebPFromBuffer(header);
|
|
76
|
+
}
|
|
77
|
+
if (this.isAVIF(header)) {
|
|
78
|
+
return this.extractAVIFFromBuffer(header);
|
|
79
|
+
}
|
|
80
|
+
throw new Error("Unsupported image format or invalid file");
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Extract metadata from file path using streaming (memory efficient)
|
|
84
|
+
*/
|
|
85
|
+
async extractFromPath(filePath, size = 4096) {
|
|
86
|
+
const stream = createReadStream(relative(this.cwd, filePath), { highWaterMark: size });
|
|
87
|
+
return this.extractFromStream(stream, size);
|
|
88
|
+
}
|
|
89
|
+
// Format detection helpers
|
|
90
|
+
isPNG(buffer) {
|
|
91
|
+
return buffer?.length >= 8 && buffer[0] === 137 && buffer[1] === 80 && buffer[2] === 78 && buffer[3] === 71 && buffer[4] === 13 && buffer[5] === 10 && buffer[6] === 26 && buffer[7] === 10;
|
|
92
|
+
}
|
|
93
|
+
isJPEG(buffer) {
|
|
94
|
+
return buffer.length >= 2 && buffer[0] === 255 && buffer[1] === 216;
|
|
95
|
+
}
|
|
96
|
+
isGIF(buffer) {
|
|
97
|
+
const header = buffer.toString("ascii", 0, 6);
|
|
98
|
+
return buffer.length >= 6 && (header === "GIF87a" || header === "GIF89a");
|
|
99
|
+
}
|
|
100
|
+
isBMP(buffer) {
|
|
101
|
+
return buffer.length >= 2 && buffer[0] === 66 && buffer[1] === 77;
|
|
102
|
+
}
|
|
103
|
+
isWebP(buffer) {
|
|
104
|
+
return buffer.length >= 12 && buffer.toString("ascii", 0, 4) === "RIFF" && buffer.toString("ascii", 8, 12) === "WEBP";
|
|
105
|
+
}
|
|
106
|
+
isAVIF(buffer) {
|
|
107
|
+
if (buffer.length < 32) return false;
|
|
108
|
+
const ftyp = buffer.toString("ascii", 4, 8);
|
|
109
|
+
if (ftyp !== "ftyp") return false;
|
|
110
|
+
const brands = buffer.toString("ascii", 8, 32);
|
|
111
|
+
return brands.includes("avif") || brands.includes("avis");
|
|
112
|
+
}
|
|
113
|
+
// Extract methods for each format (refactored from getImageSpecsWorkup)
|
|
114
|
+
extractPNGFromBuffer(buffer) {
|
|
115
|
+
if (!this.isPNG(buffer) || buffer.length < 24) {
|
|
116
|
+
throw new Error("Invalid PNG header");
|
|
117
|
+
}
|
|
118
|
+
const width = buffer.readUInt32BE(16);
|
|
119
|
+
const height = buffer.readUInt32BE(20);
|
|
120
|
+
const colorType = buffer[25];
|
|
121
|
+
let colorSpace;
|
|
122
|
+
let hasAlpha = false;
|
|
123
|
+
switch (colorType) {
|
|
124
|
+
case 0:
|
|
125
|
+
colorSpace = "grayscale";
|
|
126
|
+
break;
|
|
127
|
+
case 2:
|
|
128
|
+
colorSpace = "rgb";
|
|
129
|
+
break;
|
|
130
|
+
case 3:
|
|
131
|
+
colorSpace = "indexed";
|
|
132
|
+
break;
|
|
133
|
+
case 4:
|
|
134
|
+
colorSpace = "grayscale-alpha";
|
|
135
|
+
hasAlpha = true;
|
|
136
|
+
break;
|
|
137
|
+
case 6:
|
|
138
|
+
colorSpace = "rgba";
|
|
139
|
+
hasAlpha = true;
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
colorSpace = "unknown";
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
width,
|
|
146
|
+
height,
|
|
147
|
+
format: "png",
|
|
148
|
+
frames: 1,
|
|
149
|
+
animated: false,
|
|
150
|
+
hasAlpha,
|
|
151
|
+
orientation: null,
|
|
152
|
+
aspectRatio: width / height,
|
|
153
|
+
colorSpace,
|
|
154
|
+
iccProfile: null,
|
|
155
|
+
exifDateTimeOriginal: null
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
extractJPEGFromBuffer(buffer) {
|
|
159
|
+
if (!this.isJPEG(buffer)) {
|
|
160
|
+
throw new Error("Invalid JPEG header");
|
|
161
|
+
}
|
|
162
|
+
let pos = 2;
|
|
163
|
+
let width = 0;
|
|
164
|
+
let height = 0;
|
|
165
|
+
let colorSpace = "unknown";
|
|
166
|
+
while (pos < buffer.length - 10) {
|
|
167
|
+
if (buffer[pos] !== 255) break;
|
|
168
|
+
const marker = buffer[pos + 1];
|
|
169
|
+
if (!marker || marker === 218) break;
|
|
170
|
+
const segmentSize = buffer.readUInt16BE(pos + 2);
|
|
171
|
+
if (marker && marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
172
|
+
const numComponents = buffer[pos + 4];
|
|
173
|
+
switch (numComponents) {
|
|
174
|
+
case 1:
|
|
175
|
+
colorSpace = "grayscale";
|
|
176
|
+
break;
|
|
177
|
+
case 3:
|
|
178
|
+
colorSpace = "ycbcr";
|
|
179
|
+
break;
|
|
180
|
+
case 4:
|
|
181
|
+
colorSpace = "ycck";
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
colorSpace = "unknown";
|
|
185
|
+
}
|
|
186
|
+
height = buffer.readUInt16BE(pos + 5);
|
|
187
|
+
width = buffer.readUInt16BE(pos + 7);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
pos += segmentSize + 2;
|
|
191
|
+
if (pos >= buffer.length) break;
|
|
192
|
+
}
|
|
193
|
+
if (width === 0) {
|
|
194
|
+
throw new Error("Could not find JPEG dimensions in available data");
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
width,
|
|
198
|
+
height,
|
|
199
|
+
format: "jpeg",
|
|
200
|
+
frames: 1,
|
|
201
|
+
animated: false,
|
|
202
|
+
hasAlpha: false,
|
|
203
|
+
orientation: null,
|
|
204
|
+
aspectRatio: width / height,
|
|
205
|
+
colorSpace,
|
|
206
|
+
iccProfile: null,
|
|
207
|
+
exifDateTimeOriginal: null
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
extractGIFFromBuffer(buffer) {
|
|
211
|
+
if (!this.isGIF(buffer) || buffer.length < 10) {
|
|
212
|
+
throw new Error("Invalid GIF header");
|
|
213
|
+
}
|
|
214
|
+
const width = buffer.readUInt16LE(6);
|
|
215
|
+
const height = buffer.readUInt16LE(8);
|
|
216
|
+
let potentiallyAnimated = false;
|
|
217
|
+
if (buffer.length > 13) {
|
|
218
|
+
for (let i = 13; i < Math.min(buffer.length - 2, 100); i++) {
|
|
219
|
+
if (buffer[i] === 33 && buffer[i + 1] === 249) {
|
|
220
|
+
potentiallyAnimated = true;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
width,
|
|
227
|
+
height,
|
|
228
|
+
format: "gif",
|
|
229
|
+
frames: potentiallyAnimated ? 2 : 1,
|
|
230
|
+
// Estimate
|
|
231
|
+
animated: potentiallyAnimated,
|
|
232
|
+
hasAlpha: null,
|
|
233
|
+
orientation: null,
|
|
234
|
+
aspectRatio: width / height,
|
|
235
|
+
colorSpace: "indexed",
|
|
236
|
+
iccProfile: null,
|
|
237
|
+
exifDateTimeOriginal: null
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
extractBMPFromBuffer(buffer) {
|
|
241
|
+
if (!this.isBMP(buffer) || buffer.length < 26) {
|
|
242
|
+
throw new Error("Invalid BMP header");
|
|
243
|
+
}
|
|
244
|
+
const width = buffer.readInt32LE(18);
|
|
245
|
+
const height = Math.abs(buffer.readInt32LE(22));
|
|
246
|
+
const bitDepth = buffer.readUInt16LE(28);
|
|
247
|
+
const colorSpace = bitDepth <= 8 ? "indexed" : "rgb";
|
|
248
|
+
return {
|
|
249
|
+
width,
|
|
250
|
+
height,
|
|
251
|
+
format: "bmp",
|
|
252
|
+
frames: 1,
|
|
253
|
+
animated: false,
|
|
254
|
+
hasAlpha: null,
|
|
255
|
+
orientation: buffer.readInt32LE(22) < 0 ? 1 : 6,
|
|
256
|
+
aspectRatio: width / height,
|
|
257
|
+
colorSpace,
|
|
258
|
+
iccProfile: null,
|
|
259
|
+
exifDateTimeOriginal: null
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
extractWebPFromBuffer(buffer) {
|
|
263
|
+
if (!this.isWebP(buffer) || buffer.length < 30) {
|
|
264
|
+
throw new Error("Invalid WebP header");
|
|
265
|
+
}
|
|
266
|
+
const chunkType = buffer.toString("ascii", 12, 16);
|
|
267
|
+
let width = 0;
|
|
268
|
+
let height = 0;
|
|
269
|
+
let hasAlpha = false;
|
|
270
|
+
let animated = false;
|
|
271
|
+
let colorSpace = "rgb";
|
|
272
|
+
if (chunkType === "VP8X") {
|
|
273
|
+
const flags = buffer[20];
|
|
274
|
+
if (flags !== void 0) {
|
|
275
|
+
hasAlpha = !!(flags & 2);
|
|
276
|
+
animated = !!(flags & 1);
|
|
277
|
+
colorSpace = hasAlpha ? "rgba" : "rgb";
|
|
278
|
+
}
|
|
279
|
+
const b24 = buffer[24], b25 = buffer[25], b26 = buffer[26];
|
|
280
|
+
const b27 = buffer[27], b28 = buffer[28], b29 = buffer[29];
|
|
281
|
+
if (b24 !== void 0 && b25 !== void 0 && b26 !== void 0 && b27 !== void 0 && b28 !== void 0 && b29 !== void 0) {
|
|
282
|
+
const widthMinus1 = b24 | b25 << 8 | b26 << 16;
|
|
283
|
+
const heightMinus1 = b27 | b28 << 8 | b29 << 16;
|
|
284
|
+
width = widthMinus1 + 1;
|
|
285
|
+
height = heightMinus1 + 1;
|
|
286
|
+
}
|
|
287
|
+
} else if (chunkType === "VP8") {
|
|
288
|
+
if (buffer.length < 30) throw new Error("VP8 data too short");
|
|
289
|
+
width = buffer.readUInt16LE(26) & 16383;
|
|
290
|
+
height = buffer.readUInt16LE(28) & 16383;
|
|
291
|
+
} else if (chunkType === "VP8L") {
|
|
292
|
+
if (buffer.length < 25) throw new Error("VP8L data too short");
|
|
293
|
+
const bits = buffer.readUInt32LE(21);
|
|
294
|
+
hasAlpha = !!(bits & 1 << 8);
|
|
295
|
+
colorSpace = hasAlpha ? "rgba" : "rgb";
|
|
296
|
+
width = 1 + (bits & 16383);
|
|
297
|
+
height = 1 + (bits >> 14 & 16383);
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
width,
|
|
301
|
+
height,
|
|
302
|
+
format: "webp",
|
|
303
|
+
frames: animated ? 2 : 1,
|
|
304
|
+
// Estimate
|
|
305
|
+
animated,
|
|
306
|
+
hasAlpha,
|
|
307
|
+
orientation: null,
|
|
308
|
+
aspectRatio: width / height,
|
|
309
|
+
colorSpace,
|
|
310
|
+
iccProfile: null,
|
|
311
|
+
exifDateTimeOriginal: null
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
extractAVIFFromBuffer(buffer) {
|
|
315
|
+
if (!this.isAVIF(buffer)) {
|
|
316
|
+
throw new Error("Invalid AVIF header");
|
|
317
|
+
}
|
|
318
|
+
let width = 0;
|
|
319
|
+
let height = 0;
|
|
320
|
+
for (let i = 0; i < buffer.length - 16; i++) {
|
|
321
|
+
if (buffer.toString("ascii", i, i + 4) === "ispe") {
|
|
322
|
+
if (i + 12 < buffer.length) {
|
|
323
|
+
width = buffer.readUInt32BE(i + 8);
|
|
324
|
+
height = buffer.readUInt32BE(i + 12);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (width === 0 || height === 0) {
|
|
330
|
+
throw new Error("Could not find AVIF dimensions in available data");
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
width,
|
|
334
|
+
height,
|
|
335
|
+
format: "avif",
|
|
336
|
+
frames: 1,
|
|
337
|
+
animated: false,
|
|
338
|
+
hasAlpha: null,
|
|
339
|
+
orientation: null,
|
|
340
|
+
aspectRatio: width / height,
|
|
341
|
+
colorSpace: "rgb",
|
|
342
|
+
iccProfile: null,
|
|
343
|
+
exifDateTimeOriginal: null
|
|
344
|
+
};
|
|
345
|
+
}
|
|
13
346
|
parseExif(buffer, app1Pos, app1Size) {
|
|
14
347
|
const exifHeader = buffer.toString("ascii", app1Pos + 2, app1Pos + 8);
|
|
15
348
|
if (exifHeader !== "Exif\0\0")
|
|
@@ -73,7 +406,6 @@ var ImageService = class extends MimeService {
|
|
|
73
406
|
pos += 4;
|
|
74
407
|
let nameEnd = pos;
|
|
75
408
|
while (buffer[nameEnd] !== 0 && nameEnd < infeStart + infeSize) nameEnd++;
|
|
76
|
-
const _itemName = buffer.toString("ascii", pos, nameEnd);
|
|
77
409
|
pos = nameEnd + 1;
|
|
78
410
|
if (itemType === "mime") {
|
|
79
411
|
let ctEnd = pos;
|
|
@@ -187,7 +519,13 @@ var ImageService = class extends MimeService {
|
|
|
187
519
|
}
|
|
188
520
|
return null;
|
|
189
521
|
}
|
|
190
|
-
|
|
522
|
+
/**
|
|
523
|
+
* Legacy method that processes entire buffer
|
|
524
|
+
* Use extractFromStream or extractFromPath for better memory efficiency
|
|
525
|
+
*/
|
|
526
|
+
getImageSpecsWorkup(rawbuffer, size = 8192) {
|
|
527
|
+
const MAX_HEADER_SIZE = size;
|
|
528
|
+
const buffer = rawbuffer.subarray(0, Math.min(rawbuffer.length, MAX_HEADER_SIZE));
|
|
191
529
|
if (buffer?.length >= 24 && buffer?.[0] === 137 && buffer?.[1] === 80 && buffer?.[2] === 78 && buffer?.[3] === 71 && buffer?.[4] === 13 && buffer?.[5] === 10 && buffer?.[6] === 26 && buffer?.[7] === 10) {
|
|
192
530
|
if (buffer.readUint32BE(8) !== 13 || buffer?.[12] !== 73 || buffer?.[13] !== 72 || buffer?.[14] !== 68 || buffer?.[15] !== 82) {
|
|
193
531
|
throw new Error("IHDR Chunk of png not found or incorrect.");
|
|
@@ -306,6 +644,9 @@ var ImageService = class extends MimeService {
|
|
|
306
644
|
}
|
|
307
645
|
}
|
|
308
646
|
pos += segmentSize + 2;
|
|
647
|
+
while (pos < buffer.length - 1 && buffer[pos] === 0) {
|
|
648
|
+
pos++;
|
|
649
|
+
}
|
|
309
650
|
}
|
|
310
651
|
if (width === 0) throw new Error("No dimensions found in JPEG file");
|
|
311
652
|
return {
|
|
@@ -574,4 +915,4 @@ var ImageService = class extends MimeService {
|
|
|
574
915
|
export {
|
|
575
916
|
ImageService
|
|
576
917
|
};
|
|
577
|
-
//# sourceMappingURL=chunk-
|
|
918
|
+
//# sourceMappingURL=chunk-C2ANVZLG.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
unitsObj
|
|
3
|
+
} from "./chunk-R63XI7FS.js";
|
|
4
|
+
import {
|
|
5
|
+
FsAtomic
|
|
6
|
+
} from "./chunk-XCA34DKZ.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-FPB77OGJ.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FsFetch
|
|
3
|
+
} from "./chunk-Q2VF3BVH.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-7QVYU63E.js";
|
|
7
|
+
|
|
8
|
+
// src/fs/index.ts
|
|
9
|
+
import { createReadStream } from "fs";
|
|
10
|
+
import { relative, resolve } from "path";
|
|
11
|
+
import sharp from "sharp";
|
|
12
|
+
var Fs = class extends FsFetch {
|
|
13
|
+
constructor(cwd) {
|
|
14
|
+
super(cwd ??= process.cwd());
|
|
15
|
+
this.cwd = cwd;
|
|
16
|
+
cwd ??= process.cwd();
|
|
17
|
+
}
|
|
18
|
+
static {
|
|
19
|
+
__name(this, "Fs");
|
|
20
|
+
}
|
|
21
|
+
async getImageSpecs(filePath, size = 4096 * 6) {
|
|
22
|
+
const stream = createReadStream(relative(this.cwd, filePath), {
|
|
23
|
+
highWaterMark: size
|
|
24
|
+
});
|
|
25
|
+
return this.extractFromStream(stream, size);
|
|
26
|
+
}
|
|
27
|
+
async getImageSpecsTmp(filepath, size = 4096 * 6) {
|
|
28
|
+
const stream = createReadStream(
|
|
29
|
+
relative(this.cwd, resolve(this.tmpDir, filepath)),
|
|
30
|
+
{ highWaterMark: size }
|
|
31
|
+
);
|
|
32
|
+
return this.extractFromStream(stream);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extract image metadata using streaming (only reads ~4KB)
|
|
36
|
+
* Much more memory efficient for large images
|
|
37
|
+
*/
|
|
38
|
+
async getImageSpecsStream(filePath, size = 4096) {
|
|
39
|
+
return this.extractFromPath(filePath, size);
|
|
40
|
+
}
|
|
41
|
+
async getImageSpecsStreamTmp(filePath) {
|
|
42
|
+
return this.extractFromPath(resolve(this.tmpDir, filePath));
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @access package-private
|
|
47
|
+
*
|
|
48
|
+
* work in progress, for internal package maintainer use only
|
|
49
|
+
*/
|
|
50
|
+
// USE fluent-ffmpeg for video/animated image transforms (apng, etc)
|
|
51
|
+
// https://www.npmjs.com/package/fluent-ffmpeg
|
|
52
|
+
// https://www.npmjs.com/package/@types/fluent-ffmpeg
|
|
53
|
+
async imageTransform({
|
|
54
|
+
format,
|
|
55
|
+
target,
|
|
56
|
+
quality = 80,
|
|
57
|
+
tint,
|
|
58
|
+
resize
|
|
59
|
+
}) {
|
|
60
|
+
if (tint && !resize) {
|
|
61
|
+
return await sharp(target).toFormat(format, { quality }).tint(tint).toBuffer();
|
|
62
|
+
} else if (!tint && resize) {
|
|
63
|
+
return await sharp(target).toFormat(format, { quality }).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
64
|
+
} else if (tint && resize) {
|
|
65
|
+
return await sharp(target).toFormat(format, { quality }).tint(tint).resize(resize.widthOrOptions, resize.height, resize.options).toBuffer();
|
|
66
|
+
} else {
|
|
67
|
+
return await sharp(target).toFormat(format, { quality }).toBuffer();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export {
|
|
73
|
+
Fs
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=chunk-IU4MDHYM.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FsSize
|
|
3
|
+
} from "./chunk-FPB77OGJ.js";
|
|
4
|
+
import {
|
|
5
|
+
__name
|
|
6
|
+
} from "./chunk-7QVYU63E.js";
|
|
7
|
+
|
|
8
|
+
// src/fs-core/index.ts
|
|
9
|
+
import fsSync from "fs";
|
|
10
|
+
import fsAsync from "fs/promises";
|
|
11
|
+
import { relative } from "path";
|
|
12
|
+
var FsCore = class extends FsSize {
|
|
13
|
+
constructor(cwd) {
|
|
14
|
+
super(cwd ??= process.cwd());
|
|
15
|
+
this.cwd = cwd;
|
|
16
|
+
}
|
|
17
|
+
static {
|
|
18
|
+
__name(this, "FsCore");
|
|
19
|
+
}
|
|
20
|
+
withWs(path, data, options) {
|
|
21
|
+
try {
|
|
22
|
+
if (/\//g.test(path) === true) {
|
|
23
|
+
return this.generateDirIfDNE(this.pathHandler(path), {
|
|
24
|
+
recursive: true
|
|
25
|
+
});
|
|
26
|
+
} else return path;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(
|
|
29
|
+
`[withWs error]: `.concat(
|
|
30
|
+
typeof error === "string" ? error : JSON.stringify(error, null, 2)
|
|
31
|
+
)
|
|
32
|
+
);
|
|
33
|
+
} finally {
|
|
34
|
+
return fsSync.createWriteStream(
|
|
35
|
+
relative(this.cwd ?? process.cwd(), path),
|
|
36
|
+
typeof options !== "undefined" ? typeof options === "object" ? options : options : { autoClose: true }
|
|
37
|
+
).write(Buffer.from(Buffer.from(data).toJSON().data));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
writeFileAsync = /* @__PURE__ */ __name(async (path, data, options = {}) => {
|
|
41
|
+
try {
|
|
42
|
+
if (/\//g.test(path) === true)
|
|
43
|
+
return this.generateDirIfDNE(this.pathHandler(path), {
|
|
44
|
+
recursive: true
|
|
45
|
+
});
|
|
46
|
+
else return path;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(
|
|
49
|
+
`[writeFileAsync error]: `.concat(
|
|
50
|
+
error instanceof Error ? error.message : typeof error === "string" ? error : JSON.stringify(error, null, 2)
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
} finally {
|
|
54
|
+
const dataBuff = new Uint8Array(
|
|
55
|
+
Buffer.from(Buffer.from(data).toJSON().data)
|
|
56
|
+
);
|
|
57
|
+
return await fsAsync.writeFile(
|
|
58
|
+
relative(this.cwd, path),
|
|
59
|
+
dataBuff,
|
|
60
|
+
typeof options === "object" ? { ...options } : options
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}, "writeFileAsync");
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
FsCore
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=chunk-KDWGS5GC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UrlService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UW52DMHT.js";
|
|
4
4
|
import {
|
|
5
5
|
__name
|
|
6
6
|
} from "./chunk-7QVYU63E.js";
|
|
@@ -334,4 +334,4 @@ export {
|
|
|
334
334
|
mimeToExt,
|
|
335
335
|
MimeService
|
|
336
336
|
};
|
|
337
|
-
//# sourceMappingURL=chunk-
|
|
337
|
+
//# sourceMappingURL=chunk-KNLXF622.js.map
|