@d0paminedriven/fs 12.3.0 → 12.5.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 +0 -618
- package/dist/fs-fetch/index.d.ts +3 -3
- package/dist/mime/index.d.ts +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,620 +1,2 @@
|
|
|
1
1
|
# @d0paminedriven/fs
|
|
2
2
|
|
|
3
|
-
> **The filesystem utilities that eliminate entire categories of bugs from your codebase.**
|
|
4
|
-
|
|
5
|
-
## 🎯 Why This Package Exists
|
|
6
|
-
|
|
7
|
-
**Stop checking if directories exist.** Stop worrying about MIME types. Stop blowing up your RAM with large files. Stop writing the same filesystem boilerplate over and over.
|
|
8
|
-
|
|
9
|
-
This package solves real problems that `fs-extra` and other utilities ignore:
|
|
10
|
-
|
|
11
|
-
- ✅ **Atomic directory creation with write operations** - One method, zero directory anxiety
|
|
12
|
-
- ✅ **Intelligent MIME type handling** - Bidirectional mapping with compile-time safety
|
|
13
|
-
- ✅ **Memory-safe remote asset fetching** - Stream gigabyte files without fear
|
|
14
|
-
- ✅ **Native image dimension extraction** - Get width, height, format without dependencies
|
|
15
|
-
- ✅ **Tmp directory management** - Complete utilities for temporary file operations
|
|
16
|
-
- ✅ **Type-safe throughout** - Full TypeScript with literal types and inference
|
|
17
|
-
|
|
18
|
-
## 🚀 The Revolutionary `withWs` Method
|
|
19
|
-
|
|
20
|
-
**This single method has eliminated "directory doesn't exist" errors for 3+ years:**
|
|
21
|
-
|
|
22
|
-
```typescript
|
|
23
|
-
// What everyone else does (including fs-extra):
|
|
24
|
-
await fs.mkdir('/deep/nested/path', { recursive: true });
|
|
25
|
-
const stream = fs.createWriteStream('/deep/nested/path/file.json');
|
|
26
|
-
stream.write(data);
|
|
27
|
-
// 3 operations, multiple points of failure, mental overhead
|
|
28
|
-
|
|
29
|
-
// What withWs does:
|
|
30
|
-
fs.withWs('/deep/nested/path/file.json', data);
|
|
31
|
-
// ONE operation. Directories created atomically with write stream.
|
|
32
|
-
// No await needed. No directory checks. Just works.
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## 📦 Installation
|
|
38
|
-
|
|
39
|
-
```bash
|
|
40
|
-
pnpm add @d0paminedriven/fs
|
|
41
|
-
# or
|
|
42
|
-
npm install @d0paminedriven/fs
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## 🔥 Core Features
|
|
46
|
-
|
|
47
|
-
### 1. Smart Remote Asset Fetching
|
|
48
|
-
|
|
49
|
-
**Handles URLs without extensions intelligently:**
|
|
50
|
-
|
|
51
|
-
```typescript
|
|
52
|
-
const fs = new Fs(process.cwd());
|
|
53
|
-
|
|
54
|
-
// URLs with no extension? No problem!
|
|
55
|
-
// Automatically detects MIME type from Content-Type header
|
|
56
|
-
await fs.fetchRemoteWriteLocalLargeFiles(
|
|
57
|
-
"https://api.example.com/asset/12345", // No extension in URL
|
|
58
|
-
"public/assets/downloaded-file" // Extension auto-detected
|
|
59
|
-
);
|
|
60
|
-
// Result: public/assets/downloaded-file.png (if Content-Type was image/png)
|
|
61
|
-
|
|
62
|
-
// Streams large files without memory explosion
|
|
63
|
-
await fs.fetchRemoteWriteLocalLargeFiles(
|
|
64
|
-
"https://cdn.example.com/huge-video.mp4", // 2GB file? No problem
|
|
65
|
-
"public/videos/my-video"
|
|
66
|
-
);
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### 2. 🏆 Native Image Metadata Extraction - Beating C++ at Its Own Game
|
|
70
|
-
|
|
71
|
-
**Pure JavaScript outperforming native bindings - This is computer science perfection:**
|
|
72
|
-
|
|
73
|
-
#### 🚀 Performance That Defies Logic
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
// Stream-based extraction: Only reads first 4KB regardless of file size!
|
|
77
|
-
const metadata = await fs.getImageSpecsStream("massive-54MB-image.png");
|
|
78
|
-
// ⚡ 2.2ms for a 54MB file - That's 75x faster than buffer-based!
|
|
79
|
-
|
|
80
|
-
// Traditional buffer-based (still blazing fast):
|
|
81
|
-
const metadata = await fs.getImageSpecs("image.png");
|
|
82
|
-
// 🔥 166ms for 54MB - Still faster than most native solutions
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
#### 📊 Real-World Benchmarks - Destroying the Competition
|
|
86
|
-
|
|
87
|
-
| File | Size | Buffer Method | **Stream Method** | Speedup |
|
|
88
|
-
|------|------|--------------|-------------------|----------|
|
|
89
|
-
| PBR Texture | 53.9MB | 166.3ms | **2.2ms** | **75x** 🚀 |
|
|
90
|
-
| WebP Image | 7.5MB | 25.2ms | **0.8ms** | **32x** 🚀 |
|
|
91
|
-
| AVIF Photo | 619KB | 9.3ms | **0.6ms** | **15x** 🚀 |
|
|
92
|
-
| JPEG | 223KB | 0.8ms | **0.6ms** | **1.4x** |
|
|
93
|
-
|
|
94
|
-
**Average: 41x faster with streaming!**
|
|
95
|
-
|
|
96
|
-
#### 🧬 Why This Beats Sharp, ImageMagick, and Everything Else
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
// Sharp (C++ bindings): ~5-10ms minimum overhead
|
|
100
|
-
// ImageMagick: ~50ms for metadata extraction
|
|
101
|
-
// @d0paminedriven/fs: 0.6-2.2ms for ANY size file!
|
|
102
|
-
|
|
103
|
-
// The secret? We only read what we need:
|
|
104
|
-
// PNG header: First 33 bytes
|
|
105
|
-
// JPEG SOF: First 1-2KB
|
|
106
|
-
// WebP: First 30 bytes
|
|
107
|
-
// AVIF: First 4KB max
|
|
108
|
-
|
|
109
|
-
// Result: O(1) constant time complexity!
|
|
110
|
-
// A 10GB image takes the same 2.2ms as a 10KB image!
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
#### 💡 The Biochemist's Advantage
|
|
114
|
-
|
|
115
|
-
This implementation comes from a non-traditional developer with degrees in Biochemistry and Bio-Anthropology. The approach mirrors enzyme efficiency:
|
|
116
|
-
|
|
117
|
-
- **Traditional CS**: "How do we parse faster?"
|
|
118
|
-
- **Biochemistry approach**: "Why read the entire protein when the active site is 3 amino acids?"
|
|
119
|
-
- **Result**: Don't read 54MB when the header is 4KB!
|
|
120
|
-
|
|
121
|
-
#### 🎯 Effective Throughput: 21 GB/second
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
// Processing speed calculation:
|
|
125
|
-
// 54MB file processed in 2.2ms
|
|
126
|
-
// = 24,545 MB/second effective throughput
|
|
127
|
-
// = 24.5 GB/second of "file processing"
|
|
128
|
-
|
|
129
|
-
// Memory usage:
|
|
130
|
-
// Traditional: 54MB in memory per file
|
|
131
|
-
// Our method: 4KB in memory per file
|
|
132
|
-
// Memory savings: 99.993%!
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
#### 🏆 Production Benchmark: PBR Texture Pipeline
|
|
136
|
-
|
|
137
|
-
**Real-world test with 99 professional PBR textures:**
|
|
138
|
-
|
|
139
|
-
```ts
|
|
140
|
-
// Test setup: 99 PBR texture files
|
|
141
|
-
// - 75 JPEGs @ 4096×4096 (professional game/3D assets)
|
|
142
|
-
// - 24 PNGs @ 2048×2048 (normal maps, height maps, etc.)
|
|
143
|
-
// - Mix of diffuse, normal, roughness, metalness, AO maps
|
|
144
|
-
|
|
145
|
-
// Method used: getImageSpecs() with 24KB buffer
|
|
146
|
-
await fs.getImageSpecs(texturePath, 4096 * 6);
|
|
147
|
-
|
|
148
|
-
// Results:
|
|
149
|
-
Duration: 48.96ms for all 99 files
|
|
150
|
-
Average: 0.494ms per file
|
|
151
|
-
Throughput: 2,024 files/second
|
|
152
|
-
|
|
153
|
-
// Theoretical capacity:
|
|
154
|
-
// - 120,000+ textures per minute
|
|
155
|
-
// - Process entire AAA game asset library in seconds
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
#### Comprehensive Metadata Extraction
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
// Choose your weapon: Buffer or Stream
|
|
162
|
-
|
|
163
|
-
// Stream-based with a configurable header size (recommended for production):
|
|
164
|
-
const metadata = await fs.getImageSpecsStream("massive-image.png", 4096);
|
|
165
|
-
// ⚡ Sub-millisecond for any size file
|
|
166
|
-
|
|
167
|
-
// Buffer-based with configurable header size:
|
|
168
|
-
const metadata = await fs.getImageSpecs("texture.jpg", 4096 * 6);
|
|
169
|
-
// 🔥 Handles professional assets with extensive metadata
|
|
170
|
-
|
|
171
|
-
// Returns rich metadata:
|
|
172
|
-
{
|
|
173
|
-
width: 4096,
|
|
174
|
-
height: 4096,
|
|
175
|
-
format: 'png',
|
|
176
|
-
frames: 1,
|
|
177
|
-
animated: false,
|
|
178
|
-
hasAlpha: true,
|
|
179
|
-
orientation: null,
|
|
180
|
-
aspectRatio: 1,
|
|
181
|
-
colorSpace: 'rgba',
|
|
182
|
-
iccProfile: 'embedded',
|
|
183
|
-
exifDateTimeOriginal: '2024:01:15 14:30:00'
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
#### Supported Formats & Advanced Features
|
|
188
|
-
|
|
189
|
-
| Format | Dimensions | Color Space | Alpha | Animation | EXIF | ICC Profile |
|
|
190
|
-
|--------|------------|-------------|-------|-----------|------|-------------|
|
|
191
|
-
| PNG | ✅ | ✅ | ✅ | ✅ (APNG) | ✅ | ✅ |
|
|
192
|
-
| JPEG | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ |
|
|
193
|
-
| WebP | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
194
|
-
| GIF | ✅ | ✅ | ✅* | ✅ | ❌ | ❌ |
|
|
195
|
-
| BMP | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
|
|
196
|
-
| AVIF | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
197
|
-
|
|
198
|
-
*GIF transparency is binary (not full alpha)
|
|
199
|
-
|
|
200
|
-
#### Why This Implementation Is Revolutionary
|
|
201
|
-
|
|
202
|
-
1. **Pure Node.js** - Zero dependencies, works forever, never breaks on Node upgrades
|
|
203
|
-
2. **Stream-First Architecture** - Only reads first 4KB, not entire file
|
|
204
|
-
3. **O(1) Constant Time** - 54MB file takes same 2.2ms as 1KB file
|
|
205
|
-
4. **Faster Than Native** - Beats Sharp (C++) and ImageMagick at their own game
|
|
206
|
-
5. **Memory Efficient** - 99.993% less memory than traditional approaches
|
|
207
|
-
6. **Rich Metadata** - Complete color profiles, EXIF, ICC, animation frames
|
|
208
|
-
7. **Universal Format Support** - PNG, JPEG, WebP, GIF, BMP, AVIF all optimized
|
|
209
|
-
|
|
210
|
-
#### Real-World Use Cases
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
// Validate uploads without loading entire image
|
|
214
|
-
async function validateImageUpload(filePath: string) {
|
|
215
|
-
const meta = await fs.getImageSpecs(filePath);
|
|
216
|
-
|
|
217
|
-
if (meta.width > 4096 || meta.height > 4096) {
|
|
218
|
-
throw new Error("Image too large");
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (meta.animated && meta.frames > 100) {
|
|
222
|
-
throw new Error("Too many animation frames");
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
return meta;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// Generate responsive image sets
|
|
229
|
-
async function generateSrcSet(imagePath: string) {
|
|
230
|
-
const { width, height, format } = await fs.getImageSpecs(imagePath);
|
|
231
|
-
|
|
232
|
-
// Use dimensions to calculate breakpoints
|
|
233
|
-
const breakpoints = [width, width * 0.75, width * 0.5, width * 0.25]
|
|
234
|
-
.filter(w => w >= 320);
|
|
235
|
-
|
|
236
|
-
// Process only what's needed
|
|
237
|
-
return breakpoints;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Smart gallery organization
|
|
241
|
-
async function organizePhotoLibrary(photoDir: string) {
|
|
242
|
-
const photos = fs.readDir(photoDir);
|
|
243
|
-
const metadata = await Promise.all(
|
|
244
|
-
photos.map(async (photo) => ({
|
|
245
|
-
file: photo,
|
|
246
|
-
...await fs.getImageSpecs(`${photoDir}/${photo}`),
|
|
247
|
-
size: fs.getSize(fs.fileSize(`${photoDir}/${photo}`, "auto"))
|
|
248
|
-
}))
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
// Group by orientation, date, aspect ratio, etc.
|
|
252
|
-
const landscape = metadata.filter(m => m.aspectRatio > 1);
|
|
253
|
-
const portrait = metadata.filter(m => m.aspectRatio < 1);
|
|
254
|
-
const animated = metadata.filter(m => m.animated);
|
|
255
|
-
|
|
256
|
-
return { landscape, portrait, animated };
|
|
257
|
-
}
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
#### Technical Implementation Details
|
|
261
|
-
|
|
262
|
-
- **Stream-Based Architecture** - `createReadStream` with 4KB limit
|
|
263
|
-
- **Format-Specific Optimization** - Each format reads only its required bytes
|
|
264
|
-
- **Binary Header Parsing** - Direct buffer operations, no string conversion overhead
|
|
265
|
-
- **Native EXIF/XMP Parsing** - Full TIFF/IFD and XMP metadata extraction
|
|
266
|
-
- **Color Profile Intelligence** - ICC, sRGB, Adobe RGB, ProPhoto detection
|
|
267
|
-
- **Animation Frame Counting** - Accurate frame detection for all animated formats
|
|
268
|
-
- **Resilient Error Handling** - Gracefully handles malformed images
|
|
269
|
-
|
|
270
|
-
**The Bottom Line:** This isn't just reading image dimensions - it's proof that pure JavaScript, written by someone who thinks like a biochemist, can outperform decades of C++ optimization. The world needs to know that native bindings are no longer the answer.
|
|
271
|
-
|
|
272
|
-
### 3. Intelligent MIME Type System
|
|
273
|
-
|
|
274
|
-
```typescript
|
|
275
|
-
// Bidirectional MIME mapping with full type safety
|
|
276
|
-
const mimeType = fs.getMimeTypeForPath("file.tsx"); // "text/tsx"
|
|
277
|
-
const extension = fs.mimeToExt("application/pdf"); // "pdf"
|
|
278
|
-
|
|
279
|
-
// Handles edge cases elegantly
|
|
280
|
-
fs.getMimeTypeForPath("no-extension"); // "application/octet-stream"
|
|
281
|
-
fs.mimeToExt("image/jpeg"); // "jpg" (returns common extension)
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### 4. Tmp Directory Management Suite
|
|
285
|
-
|
|
286
|
-
```typescript
|
|
287
|
-
// Write to tmp with automatic cleanup
|
|
288
|
-
const tmpPath = fs.writeTmp("session-data.json", JSON.stringify(data));
|
|
289
|
-
|
|
290
|
-
// Generate unique tmp filenames
|
|
291
|
-
const uniqueName = fs.uniqueTmpName("upload", "bin");
|
|
292
|
-
// Result: "upload-1701234567890-x7y8z9.bin"
|
|
293
|
-
|
|
294
|
-
// Scan tmp directory (non-recursive by default to avoid permission issues)
|
|
295
|
-
const tmpFiles = fs.scanTmp("session-"); // Find all session files
|
|
296
|
-
const regexFiles = fs.scanTmp(/\.json$/); // Regex pattern support
|
|
297
|
-
|
|
298
|
-
// Remove individual tmp files with precision
|
|
299
|
-
fs.rmTmpFile("session-abc123.json"); // Targeted single file removal
|
|
300
|
-
|
|
301
|
-
// Extract files from tmp to permanent location
|
|
302
|
-
fs.extractFromTmp("processed-", "./output", {
|
|
303
|
-
cleanupAfter: true // Auto-remove from tmp after extraction
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// Cleanup old tmp files
|
|
307
|
-
fs.cleanupTmp("cache-", 60 * 60 * 1000); // Remove files older than 1 hour
|
|
308
|
-
|
|
309
|
-
// Async generator for batch removal with progress tracking
|
|
310
|
-
for await (const progress of fs.cleanTmpGenerator("upload-", 20)) {
|
|
311
|
-
// Process files in batches of 20 with real-time progress
|
|
312
|
-
console.log(`Batch ${progress.batchNumber}/${progress.totalBatches}`);
|
|
313
|
-
}
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
### 5. The Legendary `withWs` Method
|
|
317
|
-
|
|
318
|
-
```typescript
|
|
319
|
-
// Deep nested paths? Complex directory structures? Don't care.
|
|
320
|
-
fs.withWs(
|
|
321
|
-
"output/2024/reports/january/week-1/summary.json",
|
|
322
|
-
JSON.stringify(reportData)
|
|
323
|
-
);
|
|
324
|
-
// Creates all 5 directories if needed, writes file, done.
|
|
325
|
-
|
|
326
|
-
// Works with any data type
|
|
327
|
-
fs.withWs("public/images/avatar.png", imageBuffer);
|
|
328
|
-
fs.withWs("logs/error.log", "Error: " + errorMessage);
|
|
329
|
-
fs.withWs("data/binary.dat", binaryData);
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
---
|
|
333
|
-
|
|
334
|
-
## 🎨 Real-World Examples
|
|
335
|
-
|
|
336
|
-
### Image Asset Pipeline
|
|
337
|
-
|
|
338
|
-
```typescript
|
|
339
|
-
const fs = new Fs(process.cwd());
|
|
340
|
-
|
|
341
|
-
async function processImageAssets() {
|
|
342
|
-
// Fetch remote images with automatic extension detection
|
|
343
|
-
const imageUrls = [
|
|
344
|
-
"https://api.unsplash.com/photos/random", // No extension!
|
|
345
|
-
"https://cdn.example.com/hero-image", // No extension!
|
|
346
|
-
"https://example.com/logo.avif" // Has extension
|
|
347
|
-
];
|
|
348
|
-
|
|
349
|
-
for (const url of imageUrls) {
|
|
350
|
-
// Extension auto-detected from Content-Type
|
|
351
|
-
await fs.fetchRemoteWriteLocalLargeFiles(
|
|
352
|
-
url,
|
|
353
|
-
`public/images/${Date.now()}`
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// Get dimensions for all downloaded images
|
|
358
|
-
const images = fs.readDir("public/images");
|
|
359
|
-
const metadata = images.map(img => ({
|
|
360
|
-
file: img,
|
|
361
|
-
...fs.getImageSpecs(`public/images/${img}`),
|
|
362
|
-
size: fs.getSize(`public/images/${img}`)
|
|
363
|
-
}));
|
|
364
|
-
|
|
365
|
-
// Generate TypeScript metadata file
|
|
366
|
-
fs.withWs(
|
|
367
|
-
"src/generated/image-metadata.ts",
|
|
368
|
-
`export const imageMetadata = ${JSON.stringify(metadata, null, 2)} as const;`
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
### Temporary File Processing
|
|
374
|
-
|
|
375
|
-
```typescript
|
|
376
|
-
async function processUpload(fileBuffer: Buffer, userId: string) {
|
|
377
|
-
const fs = new Fs(process.cwd());
|
|
378
|
-
|
|
379
|
-
// Generate unique tmp filename
|
|
380
|
-
const tmpName = fs.uniqueTmpName(`upload-${userId}`, "dat");
|
|
381
|
-
|
|
382
|
-
// Write to tmp for processing
|
|
383
|
-
const tmpPath = fs.writeTmp(tmpName, fileBuffer);
|
|
384
|
-
|
|
385
|
-
// Process the file (resize, convert, etc.)
|
|
386
|
-
const processed = await processFile(tmpPath);
|
|
387
|
-
|
|
388
|
-
// Move to permanent storage
|
|
389
|
-
fs.withWs(`uploads/${userId}/${Date.now()}.jpg`, processed);
|
|
390
|
-
|
|
391
|
-
// Cleanup tmp (or let cleanupTmp handle it later)
|
|
392
|
-
fs.cleanupTmp(`upload-${userId}`);
|
|
393
|
-
}
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
### Advanced Tmp Management
|
|
397
|
-
|
|
398
|
-
#### Granular Single File Removal
|
|
399
|
-
```typescript
|
|
400
|
-
const fs = new Fs(process.cwd());
|
|
401
|
-
|
|
402
|
-
// Create some tmp files
|
|
403
|
-
const tmpFile1 = fs.uniqueTmpName("session", "json");
|
|
404
|
-
const tmpFile2 = fs.uniqueTmpName("cache", "dat");
|
|
405
|
-
fs.writeTmp(tmpFile1, JSON.stringify({ user: "123" }));
|
|
406
|
-
fs.writeTmp(tmpFile2, Buffer.from("cached data"));
|
|
407
|
-
|
|
408
|
-
// Remove a specific tmp file
|
|
409
|
-
fs.rmTmpFile(tmpFile1); // Removes only session-*.json file
|
|
410
|
-
|
|
411
|
-
// Or find and remove specific files
|
|
412
|
-
const sessionFiles = fs.scanTmp("session");
|
|
413
|
-
sessionFiles.forEach(file => fs.rmTmpFile(file));
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
#### Batch Removal with Progress Tracking
|
|
417
|
-
```typescript
|
|
418
|
-
async function cleanupWithProgress() {
|
|
419
|
-
const fs = new Fs(process.cwd());
|
|
420
|
-
|
|
421
|
-
// Clean tmp files in batches with real-time progress
|
|
422
|
-
for await (const progress of fs.cleanTmpGenerator("upload-", 25)) {
|
|
423
|
-
if (progress.action === 'removing') {
|
|
424
|
-
console.log(`Processing batch ${progress.batchNumber}/${progress.totalBatches}`);
|
|
425
|
-
console.log(`Files in batch: ${progress.batch.length}`);
|
|
426
|
-
} else if (progress.action === 'batch-complete') {
|
|
427
|
-
console.log(`Batch complete! Removed: ${progress.totalRemoved}`);
|
|
428
|
-
console.log(`Remaining: ${progress.remaining}`);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
// Using regex patterns for more complex matching
|
|
434
|
-
async function cleanupPatterns() {
|
|
435
|
-
const fs = new Fs(process.cwd());
|
|
436
|
-
|
|
437
|
-
// Match multiple patterns with regex
|
|
438
|
-
const pattern = /(session|cache|upload)-.*/;
|
|
439
|
-
|
|
440
|
-
for await (const progress of fs.cleanTmpGenerator(pattern, 50)) {
|
|
441
|
-
// Process large batches of 50 files at a time
|
|
442
|
-
if (progress.action === 'batch-complete') {
|
|
443
|
-
console.log(`Batch ${progress.batchNumber}: Removed ${progress.batchSize} files`);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
### Build-Time Asset Generation
|
|
450
|
-
|
|
451
|
-
```typescript
|
|
452
|
-
// Generate a manifest of all assets with sizes and dimensions
|
|
453
|
-
function generateAssetManifest() {
|
|
454
|
-
const fs = new Fs(process.cwd());
|
|
455
|
-
const assets: Record<string, any> = {};
|
|
456
|
-
|
|
457
|
-
// Scan all asset directories
|
|
458
|
-
const images = fs.readDir("public/images", { recursive: true });
|
|
459
|
-
const videos = fs.readDir("public/videos", { recursive: true });
|
|
460
|
-
|
|
461
|
-
// Process images
|
|
462
|
-
images.forEach(img => {
|
|
463
|
-
const path = `public/images/${img}`;
|
|
464
|
-
assets[img] = {
|
|
465
|
-
type: "image",
|
|
466
|
-
mime: fs.getMimeTypeForPath(img),
|
|
467
|
-
size: fs.autoFileSizeRaw(path),
|
|
468
|
-
dimensions: fs.getImageSpecs(path)
|
|
469
|
-
};
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
// Process videos
|
|
473
|
-
videos.forEach(vid => {
|
|
474
|
-
const path = `public/videos/${vid}`;
|
|
475
|
-
assets[vid] = {
|
|
476
|
-
type: "video",
|
|
477
|
-
mime: fs.getMimeTypeForPath(vid),
|
|
478
|
-
size: fs.autoFileSizeRaw(path)
|
|
479
|
-
};
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
// Write manifest (directories auto-created)
|
|
483
|
-
fs.withWs(
|
|
484
|
-
"src/generated/assets/manifest.json",
|
|
485
|
-
JSON.stringify(assets, null, 2)
|
|
486
|
-
);
|
|
487
|
-
}
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
## 📊 Performance & Architecture
|
|
491
|
-
|
|
492
|
-
### Why It's Fast
|
|
493
|
-
|
|
494
|
-
- **Stream-based file operations** - Never loads entire files into memory
|
|
495
|
-
- **Parallel directory creation** - Uses `finally` blocks for guaranteed execution
|
|
496
|
-
- **Zero unnecessary checks** - No redundant `fs.exists()` calls
|
|
497
|
-
- **Optimized MIME lookups** - O(1) bidirectional mapping with Map structures
|
|
498
|
-
|
|
499
|
-
### Memory Safety
|
|
500
|
-
|
|
501
|
-
```typescript
|
|
502
|
-
// This won't blow up your RAM, even with a 10GB file
|
|
503
|
-
await fs.fetchRemoteWriteLocalLargeFiles(
|
|
504
|
-
"https://example.com/massive-file.zip",
|
|
505
|
-
"downloads/massive-file"
|
|
506
|
-
);
|
|
507
|
-
|
|
508
|
-
// Internally uses streams:
|
|
509
|
-
// response.body.pipe(fs.createWriteStream(path))
|
|
510
|
-
// Instead of loading entire file into memory
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
## 🛠️ Complete API Reference
|
|
514
|
-
|
|
515
|
-
### Core Methods
|
|
516
|
-
|
|
517
|
-
| Method | Description | Returns |
|
|
518
|
-
|--------|-------------|---------|
|
|
519
|
-
| `withWs(path, data, options?)` | Write with automatic directory creation | `WriteStream` |
|
|
520
|
-
| `writeFileAsync(path, data)` | Async file write with directory creation | `Promise<void>` |
|
|
521
|
-
| `readDir(path, options?)` | Read directory contents | `string[]` |
|
|
522
|
-
| `fileToBuffer(path)` | Read file as Buffer | `Buffer` |
|
|
523
|
-
| `exists(path)` | Check if path exists | `boolean` |
|
|
524
|
-
| `rmFile(path)` | Remove file | `void` |
|
|
525
|
-
| `rmDirSync(path)` | Remove directory | `void` |
|
|
526
|
-
|
|
527
|
-
### Remote Operations
|
|
528
|
-
|
|
529
|
-
| Method | Description | Returns |
|
|
530
|
-
|--------|-------------|---------|
|
|
531
|
-
| `fetchRemoteWriteLocalLargeFiles(url, outputPath)` | Stream remote file to disk | `Promise<void>` |
|
|
532
|
-
| `assetToBufferView(url)` | Fetch remote asset as buffer | `Promise<{buffer, b64, mime}>` |
|
|
533
|
-
|
|
534
|
-
### Image Operations
|
|
535
|
-
|
|
536
|
-
| Method | Description | Returns |
|
|
537
|
-
|--------|-------------|---------|
|
|
538
|
-
| `getImageSpecs(path)` | Extract image metadata (buffer-based) | `ImageSpecs` |
|
|
539
|
-
| `getImageSpecsStream(path)` | Extract image metadata (stream-based, 4KB only) | `ImageSpecs` |
|
|
540
|
-
| `imageTransform(target, options)` | Transform images with Sharp | `Promise<Buffer>` |
|
|
541
|
-
| `cleanDataUrl(dataUrl)` | Strip data URL prefix | `string` |
|
|
542
|
-
| `b64ToBlob(b64, mime?)` | Convert base64 to Blob | `Blob` |
|
|
543
|
-
|
|
544
|
-
### MIME Operations
|
|
545
|
-
|
|
546
|
-
| Method | Description | Returns |
|
|
547
|
-
|--------|-------------|---------|
|
|
548
|
-
| `getMimeTypeForPath(path)` | Get MIME type from file path | `string` |
|
|
549
|
-
| `mimeToExt(mime)` | Convert MIME to extension | `string` |
|
|
550
|
-
| `getExtensionForMimeType(mime)` | Get extension from MIME | `string \| undefined` |
|
|
551
|
-
|
|
552
|
-
### Tmp Directory Operations
|
|
553
|
-
|
|
554
|
-
| Method | Description | Returns |
|
|
555
|
-
|--------|-------------|---------|
|
|
556
|
-
| `writeTmp(filename, data)` | Write to tmp directory | `string` (path) |
|
|
557
|
-
| `readTmp(filename)` | Read from tmp directory | `Buffer` |
|
|
558
|
-
| `scanTmp(pattern?)` | List tmp directory contents | `string[]` |
|
|
559
|
-
| `extractFromTmp(pattern, target, options?)` | Extract files from tmp | `string[]` |
|
|
560
|
-
| `cleanupTmp(pattern, maxAge?)` | Remove tmp files | `number` (removed) |
|
|
561
|
-
| `uniqueTmpName(prefix?, ext?)` | Generate unique tmp filename | `string` |
|
|
562
|
-
|
|
563
|
-
### Utility Methods
|
|
564
|
-
|
|
565
|
-
| Method | Description | Returns |
|
|
566
|
-
|--------|-------------|---------|
|
|
567
|
-
| `wait(ms)` | Async delay utility | `Promise<void>` |
|
|
568
|
-
| `getSize(path)` | Human-readable file size | `string` |
|
|
569
|
-
| `fileSizeMb(path)` | File size in MB | `number` |
|
|
570
|
-
| `autoFileSizeRaw(path)` | Auto-formatted size object | `{size, unit}` |
|
|
571
|
-
| `chunkArray(array, size)` | Split array into chunks | `T[][]` |
|
|
572
|
-
|
|
573
|
-
## 🚦 Migration Guide
|
|
574
|
-
|
|
575
|
-
### From fs-extra
|
|
576
|
-
|
|
577
|
-
```typescript
|
|
578
|
-
// Before (fs-extra)
|
|
579
|
-
await fs.ensureDir('/path/to/dir');
|
|
580
|
-
await fs.writeFile('/path/to/dir/file.json', data);
|
|
581
|
-
|
|
582
|
-
// After (@d0paminedriven/fs)
|
|
583
|
-
fs.withWs('/path/to/dir/file.json', data);
|
|
584
|
-
```
|
|
585
|
-
|
|
586
|
-
### From Native fs
|
|
587
|
-
|
|
588
|
-
```typescript
|
|
589
|
-
// Before (native fs)
|
|
590
|
-
import { mkdir, writeFile } from 'fs/promises';
|
|
591
|
-
await mkdir('/path/to/dir', { recursive: true });
|
|
592
|
-
await writeFile('/path/to/dir/file.json', data);
|
|
593
|
-
|
|
594
|
-
// After (@d0paminedriven/fs)
|
|
595
|
-
fs.withWs('/path/to/dir/file.json', data);
|
|
596
|
-
```
|
|
597
|
-
|
|
598
|
-
## 💡 Philosophy
|
|
599
|
-
|
|
600
|
-
This package embodies a simple philosophy: **filesystem operations should be atomic, safe, and obvious**.
|
|
601
|
-
|
|
602
|
-
- **Atomic**: Operations either fully succeed or fully fail
|
|
603
|
-
- **Safe**: No memory explosions, no race conditions
|
|
604
|
-
- **Obvious**: One method does one thing well
|
|
605
|
-
|
|
606
|
-
The `withWs` method is the crown jewel - it eliminates an entire category of bugs (missing directories) that plague every Node.js application. After using it for 3+ years, the creator literally forgot that "directory doesn't exist" errors were even a thing.
|
|
607
|
-
|
|
608
|
-
---
|
|
609
|
-
|
|
610
|
-
|npm |downloads| github|
|
|
611
|
-
|:----:|:----:|:------:|
|
|
612
|
-
| [](https://www.npmjs.com/package/@d0paminedriven/fs) | [](https://www.npmjs.com/package/@d0paminedriven/fs) | <a style="fill:white;width:100%;height:100dvh;" href="https://github.com/DopamineDriven/d0paminedriven/tree/master/packages/fs"><svg height="24" aria-hidden="true" viewBox="0 0 24 24" version="1.1" width="24" data-view-component="true" class="octicon octicon-mark-github"><path d="M12 1C5.9225 1 1 5.9225 1 12C1 16.8675 4.14875 20.9787 8.52125 22.4362C9.07125 22.5325 9.2775 22.2025 9.2775 21.9137C9.2775 21.6525 9.26375 20.7862 9.26375 19.865C6.5 20.3737 5.785 19.1912 5.565 18.5725C5.44125 18.2562 4.905 17.28 4.4375 17.0187C4.0525 16.8125 3.5025 16.3037 4.42375 16.29C5.29 16.2762 5.90875 17.0875 6.115 17.4175C7.105 19.0812 8.68625 18.6137 9.31875 18.325C9.415 17.61 9.70375 17.1287 10.02 16.8537C7.5725 16.5787 5.015 15.63 5.015 11.4225C5.015 10.2262 5.44125 9.23625 6.1425 8.46625C6.0325 8.19125 5.6475 7.06375 6.2525 5.55125C6.2525 5.55125 7.17375 5.2625 9.2775 6.67875C10.1575 6.43125 11.0925 6.3075 12.0275 6.3075C12.9625 6.3075 13.8975 6.43125 14.7775 6.67875C16.8813 5.24875 17.8025 5.55125 17.8025 5.55125C18.4075 7.06375 18.0225 8.19125 17.9125 8.46625C18.6138 9.23625 19.04 10.2125 19.04 11.4225C19.04 15.6437 16.4688 16.5787 14.0213 16.8537C14.42 17.1975 14.7638 17.8575 14.7638 18.8887C14.7638 20.36 14.75 21.5425 14.75 21.9137C14.75 22.2025 14.9563 22.5462 15.5063 22.4362C19.8513 20.9787 23 16.8537 23 12C23 5.9225 18.0775 1 12 1Z"></path></svg></a>
|
|
613
|
-
|
|
614
|
-
## 📜 License
|
|
615
|
-
|
|
616
|
-
MIT © [DopamineDriven](https://github.com/DopamineDriven)
|
|
617
|
-
|
|
618
|
-
---
|
|
619
|
-
|
|
620
|
-
**Built with frustration, refined with experience, shared with love.** 🚀
|
package/dist/fs-fetch/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ export declare class FsFetch extends FsTmp {
|
|
|
3
3
|
cwd: string;
|
|
4
4
|
constructor(cwd: string);
|
|
5
5
|
assetToBuffer<const T extends string>(path: T): Promise<{
|
|
6
|
-
readonly b64encodedData: `data:
|
|
7
|
-
readonly extension: "
|
|
6
|
+
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:text/x-c;base64, ${string}` | `data:application/x-cdf;base64, ${string}` | `data:text/javascript;base64, ${string}` | `data:application/node;base64, ${string}` | `data:text/x-c++;base64, ${string}` | `data:text/x-csharp;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:text/x-go;base64, ${string}` | `data:application/gzip;base64, ${string}` | `data:application/x-gzip;base64, ${string}` | `data:image/heic;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:text/x-java;base64, ${string}` | `data:image/jpeg;base64, ${string}` | `data:application/json;base64, ${string}` | `data:application/jsonl;base64, ${string}` | `data:text/x-jsonl;base64, ${string}` | `data:application/ld+json;base64, ${string}` | `data:application/jsonc;base64, ${string}` | `data:application/json5;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:text/x-php;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:text/x-script.python;base64, ${string}` | `data:application/x-python-code;base64, ${string}` | `data:application/vnd.rar;base64, ${string}` | `data:text/x-ruby;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:text/x-tex;base64, ${string}` | `data:image/tiff;base64, ${string}` | `data:application/toml;base64, ${string}` | `data:text/typescript;base64, ${string}` | `data:application/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}`;
|
|
7
|
+
readonly extension: "mpd" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonc" | "jsonl" | "jsonlines" | "json5" | "jsonld" | "webmanifest" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "md" | "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" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "weba" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "avif" | "bmp" | "dpx" | "emf" | "gif" | "heic" | "jpg" | "jpeg" | "ktx" | "ktx2" | "png" | "svg" | "tiff" | "ico" | "webp" | "cur" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "htm" | "cjs" | "mjs" | "vtt" | "c" | "cpp" | "cs" | "go" | "java" | "rb" | "tex" | "3gp" | "3g2" | "mp4" | "m4v" | "m4s" | "mpeg" | "ogv" | "avi" | "jfif" | "jif" | "jpe" | "mtlx" | "pk1" | "pjp" | "pjpeg" | "tif" | "webm";
|
|
8
8
|
}>;
|
|
9
9
|
assetToBufferView<const T extends string>(path: T): Promise<{
|
|
10
10
|
readonly b64encodedData: string;
|
|
11
|
-
readonly extension: "
|
|
11
|
+
readonly extension: "mpd" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonc" | "jsonl" | "jsonlines" | "json5" | "jsonld" | "webmanifest" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "md" | "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" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "weba" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "avif" | "bmp" | "dpx" | "emf" | "gif" | "heic" | "jpg" | "jpeg" | "ktx" | "ktx2" | "png" | "svg" | "tiff" | "ico" | "webp" | "cur" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "htm" | "cjs" | "mjs" | "vtt" | "c" | "cpp" | "cs" | "go" | "java" | "rb" | "tex" | "3gp" | "3g2" | "mp4" | "m4v" | "m4s" | "mpeg" | "ogv" | "avi" | "jfif" | "jif" | "jpe" | "mtlx" | "pk1" | "pjp" | "pjpeg" | "tif" | "webm" | undefined;
|
|
12
12
|
}>;
|
|
13
13
|
/**
|
|
14
14
|
*
|
package/dist/mime/index.d.ts
CHANGED
|
@@ -543,15 +543,15 @@ export declare class MimeService extends UrlService {
|
|
|
543
543
|
compareMimeToExt(p?: "mime" | "ext"): {
|
|
544
544
|
[k: string]: number;
|
|
545
545
|
};
|
|
546
|
-
mimeToExt(mime: keyof typeof this.toExtObj): "
|
|
547
|
-
assetType<const T extends string>(url: T): "
|
|
546
|
+
mimeToExt(mime: keyof typeof this.toExtObj): "mpd" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonc" | "jsonl" | "json5" | "jsonld" | "webmanifest" | "doc" | "node" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "md" | "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" | "yml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "wav" | "weba" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "aces" | "apng" | "avci" | "avif" | "bmp" | "dpx" | "emf" | "gif" | "heic" | "jpg" | "ktx" | "ktx2" | "png" | "svg" | "tiff" | "ico" | "webp" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "cjs" | "vtt" | "c" | "cpp" | "cs" | "go" | "java" | "rb" | "tex" | "3gp" | "3g2" | "mp4" | "mpeg" | "ogv" | "avi";
|
|
547
|
+
assetType<const T extends string>(url: T): "mpd" | "epub" | "ttf" | "gz" | "jar" | "json" | "jsonc" | "jsonl" | "jsonlines" | "json5" | "jsonld" | "webmanifest" | "doc" | "node" | "js" | "bin" | "obj" | "ogx" | "pdf" | "rtf" | "sql" | "md" | "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" | "yml" | "yaml" | "aac" | "mid" | "m4a" | "mp3" | "opus" | "ogg" | "oga" | "wav" | "weba" | "midi" | "otf" | "woff" | "woff2" | "hjif" | "hmpg" | "ivs" | "ivt" | "aces" | "apng" | "avci" | "avif" | "bmp" | "dpx" | "emf" | "gif" | "heic" | "jpg" | "jpeg" | "ktx" | "ktx2" | "png" | "svg" | "tiff" | "ico" | "webp" | "cur" | "glb" | "gltf" | "usdz" | "ics" | "css" | "csv" | "sse" | "ts" | "rs" | "py" | "txt" | "html" | "htm" | "cjs" | "mjs" | "vtt" | "c" | "cpp" | "cs" | "go" | "java" | "rb" | "tex" | "3gp" | "3g2" | "mp4" | "m4v" | "m4s" | "mpeg" | "ogv" | "avi" | "jfif" | "jif" | "jpe" | "mtlx" | "pk1" | "pjp" | "pjpeg" | "tif" | "webm" | undefined;
|
|
548
548
|
getMimes<const E extends FileExtension>(ext: E): readonly ["audio/aac"] | readonly ["application/x-abiword"] | readonly ["image/aces"] | readonly ["image/apng"] | readonly ["application/x-freearc"] | readonly ["image/avci"] | readonly ["image/avif"] | readonly ["video/x-msvideo"] | readonly ["application/vnd.amazon.ebook"] | readonly ["application/octet-stream", "multipart/voice-message"] | readonly ["image/bmp"] | readonly ["application/x-bzip"] | readonly ["application/x-bzip2"] | readonly ["text/x-c"] | readonly ["application/x-cdf"] | readonly ["text/javascript", "application/node"] | readonly ["text/x-c++"] | readonly ["text/x-csharp"] | readonly ["application/x-csh"] | readonly ["text/css"] | readonly ["text/csv"] | readonly ["image/x-icon"] | readonly ["application/msword"] | readonly ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"] | readonly ["image/dpx"] | readonly ["image/emf"] | readonly ["application/vnd.ms-fontobject"] | readonly ["application/epub+zip"] | readonly ["image/gif"] | readonly ["model/gltf-binary"] | readonly ["model/gltf+json"] | readonly ["text/x-go"] | readonly ["application/gzip", "application/x-gzip"] | readonly ["image/heic"] | readonly ["haptics/hjif"] | readonly ["haptics/hmpg"] | readonly ["text/html"] | readonly ["image/vnd.microsoft.icon", "image/x-icon"] | readonly ["text/calendar"] | readonly ["haptics/ivs"] | readonly ["application/java-archive"] | readonly ["text/x-java"] | readonly ["image/jpeg"] | readonly ["application/json"] | readonly ["application/jsonl", "text/x-jsonl"] | readonly ["application/ld+json"] | readonly ["application/json", "application/jsonc"] | readonly ["application/json", "application/json5"] | readonly ["image/ktx"] | readonly ["image/ktx2"] | readonly ["application/vnd.apple.mpegurl"] | readonly ["audio/mp4"] | readonly ["video/mp4"] | readonly ["text/markdown"] | readonly ["application/x-mdx"] | readonly ["audio/midi"] | readonly ["audio/x-midi"] | readonly ["text/javascript"] | readonly ["audio/mpeg"] | readonly ["application/dash+xml"] | readonly ["video/mpeg"] | readonly ["application/vnd.apple.installer+xml"] | readonly ["application/xml"] | readonly ["application/x-ndjson"] | readonly ["application/node", "text/javascript"] | readonly ["model/obj", "application/octet-stream", "text/plain"] | readonly ["application/vnd.oasis.opendocument.presentation"] | readonly ["application/vnd.oasis.opendocument.spreadsheet"] | readonly ["application/vnd.oasis.opendocument.text"] | readonly ["audio/ogg"] | readonly ["video/ogg"] | readonly ["application/ogg"] | readonly ["font/otf"] | readonly ["application/octet-stream"] | readonly ["image/png"] | readonly ["application/pdf"] | readonly ["text/x-php", "application/x-httpd-php"] | readonly ["application/vnd.apple.pkpass"] | readonly ["application/vnd.ms-powerpoint"] | readonly ["application/vnd.openxmlformats-officedocument.presentationml.presentation"] | readonly ["text/x-python", "text/x-script.python"] | readonly ["application/x-python-code"] | readonly ["application/vnd.rar"] | readonly ["text/x-ruby"] | readonly ["text/rust"] | readonly ["application/rtf"] | readonly ["application/x-sh"] | readonly ["application/sql"] | readonly ["text/event-stream"] | readonly ["image/svg+xml"] | readonly ["application/x-tar"] | readonly ["text/x-tex"] | readonly ["image/tiff"] | readonly ["application/toml"] | readonly ["text/typescript", "application/typescript", "video/mp2t", "video/vnd.dlna.mpeg-tts"] | readonly ["application/font-sfnt", "font/ttf"] | readonly ["text/plain"] | readonly ["model/vnd.usdz+zip"] | readonly ["application/vnd.visio"] | readonly ["text/vtt"] | readonly ["application/wasm"] | readonly ["audio/wav"] | readonly ["audio/webm"] | readonly ["video/webm"] | readonly ["application/manifest+json"] | readonly ["image/webp"] | readonly ["font/woff"] | readonly ["font/woff2"] | readonly ["application/xhtml+xml"] | readonly ["application/vnd.ms-excel"] | readonly ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"] | readonly ["application/xml", "text/xml"] | readonly ["application/vnd.mozilla.xul+xml"] | readonly ["application/yaml"] | readonly ["application/zip", "application/x-zip-compressed"] | readonly ["video/3gpp"] | readonly ["video/3gpp2"] | readonly ["application/x-7z-compressed"];
|
|
549
549
|
getMimeFor<const E extends FileExtension>(ext: E, opts?: {
|
|
550
550
|
type?: MimeTopLevelType;
|
|
551
551
|
}): FileExtensionToMimeType<E>;
|
|
552
|
-
isMimeFor<const E extends FileExtension>(ext: E, mime: FileExtensionToMimeType<E>): "
|
|
552
|
+
isMimeFor<const E extends FileExtension>(ext: E, mime: FileExtensionToMimeType<E>): "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "multipart/voice-message" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "text/x-c" | "application/x-cdf" | "text/javascript" | "application/node" | "text/x-c++" | "text/x-csharp" | "application/x-csh" | "text/css" | "text/csv" | "image/x-icon" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "text/x-go" | "application/gzip" | "application/x-gzip" | "image/heic" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "text/x-java" | "image/jpeg" | "application/json" | "application/jsonl" | "text/x-jsonl" | "application/ld+json" | "application/jsonc" | "application/json5" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "application/dash+xml" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/xml" | "application/x-ndjson" | "model/obj" | "text/plain" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "text/x-php" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "text/x-script.python" | "application/x-python-code" | "application/vnd.rar" | "text/x-ruby" | "text/rust" | "application/rtf" | "application/x-sh" | "application/sql" | "text/event-stream" | "image/svg+xml" | "application/x-tar" | "text/x-tex" | "image/tiff" | "application/toml" | "text/typescript" | "application/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "audio/webm" | "video/webm" | "application/manifest+json" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "text/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed" | undefined;
|
|
553
553
|
getMimeTypeForPath<T extends string>(path: T, opts?: {
|
|
554
554
|
type?: MimeTopLevelType;
|
|
555
|
-
}): "
|
|
555
|
+
}): "audio/aac" | "application/x-abiword" | "image/aces" | "image/apng" | "application/x-freearc" | "image/avci" | "image/avif" | "video/x-msvideo" | "application/vnd.amazon.ebook" | "application/octet-stream" | "multipart/voice-message" | "image/bmp" | "application/x-bzip" | "application/x-bzip2" | "text/x-c" | "application/x-cdf" | "text/javascript" | "application/node" | "text/x-c++" | "text/x-csharp" | "application/x-csh" | "text/css" | "text/csv" | "image/x-icon" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "image/dpx" | "image/emf" | "application/vnd.ms-fontobject" | "application/epub+zip" | "image/gif" | "model/gltf-binary" | "model/gltf+json" | "text/x-go" | "application/gzip" | "application/x-gzip" | "image/heic" | "haptics/hjif" | "haptics/hmpg" | "text/html" | "image/vnd.microsoft.icon" | "text/calendar" | "haptics/ivs" | "application/java-archive" | "text/x-java" | "image/jpeg" | "application/json" | "application/jsonl" | "text/x-jsonl" | "application/ld+json" | "application/jsonc" | "application/json5" | "image/ktx" | "image/ktx2" | "application/vnd.apple.mpegurl" | "audio/mp4" | "video/mp4" | "text/markdown" | "application/x-mdx" | "audio/midi" | "audio/x-midi" | "audio/mpeg" | "application/dash+xml" | "video/mpeg" | "application/vnd.apple.installer+xml" | "application/xml" | "application/x-ndjson" | "model/obj" | "text/plain" | "application/vnd.oasis.opendocument.presentation" | "application/vnd.oasis.opendocument.spreadsheet" | "application/vnd.oasis.opendocument.text" | "audio/ogg" | "video/ogg" | "application/ogg" | "font/otf" | "image/png" | "application/pdf" | "text/x-php" | "application/x-httpd-php" | "application/vnd.apple.pkpass" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "text/x-python" | "text/x-script.python" | "application/x-python-code" | "application/vnd.rar" | "text/x-ruby" | "text/rust" | "application/rtf" | "application/x-sh" | "application/sql" | "text/event-stream" | "image/svg+xml" | "application/x-tar" | "text/x-tex" | "image/tiff" | "application/toml" | "text/typescript" | "application/typescript" | "video/mp2t" | "video/vnd.dlna.mpeg-tts" | "application/font-sfnt" | "font/ttf" | "model/vnd.usdz+zip" | "application/vnd.visio" | "text/vtt" | "application/wasm" | "audio/wav" | "audio/webm" | "video/webm" | "application/manifest+json" | "image/webp" | "font/woff" | "font/woff2" | "application/xhtml+xml" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "text/xml" | "application/vnd.mozilla.xul+xml" | "application/yaml" | "application/zip" | "application/x-zip-compressed" | "video/3gpp" | "video/3gpp2" | "application/x-7z-compressed";
|
|
556
556
|
}
|
|
557
557
|
//# sourceMappingURL=index.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d0paminedriven/fs",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.0",
|
|
4
4
|
"homepage": "https://github.com/DopamineDriven/d0paminedriven/blob/master/packages/fs/README.md",
|
|
5
5
|
"author": "Andrew Ross",
|
|
6
6
|
"description": "convenient fs helpers",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"./utils": "./dist/utils/index.js"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@d0paminedriven/mimedown": "^0.
|
|
117
|
+
"@d0paminedriven/mimedown": "^0.6.0",
|
|
118
118
|
"@d0paminedriven/pdfdown": "^0.20.0",
|
|
119
119
|
"dotenv": "^18.0.10",
|
|
120
120
|
"dotenv-expand": "^1000.0.0",
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
"tslib": "^2.9.1",
|
|
135
135
|
"tsx": "^4.23.15",
|
|
136
136
|
"typescript": "^6.0.3",
|
|
137
|
-
"typescript-eslint": "^8.
|
|
137
|
+
"typescript-eslint": "^8.74.0"
|
|
138
138
|
},
|
|
139
139
|
"prettier": "@d0paminedriven/prettier-config",
|
|
140
140
|
"scripts": {
|