基于 SOC 职业分类
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill file-handling命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
Bun runtime: HTTP server, file I/O, SQLite, test runner, package manager, bundler — all-in-one JS toolchain.
Clerk: Drop-in auth UI, Organizations, User management, JWT templates, webhooks, Next.js middleware integration.
Gelişmiş masaüstü, tarayıcı ve işletim sistemi kontrol yeteneği. Görsel (koordinat tabanlı) fare/klavye otomasyonu, DOM manipülasyonu, pencere yönetimi, gelişmiş dosya, ağ ve süreç yönetimini kapsar.
| name | file-handling |
| description | File handling: Upload strategy, storage patterns, CDN integration, processing. |
| triggers | {"extensions":[".ts"],"keywords":["fs","file","upload","stream","multer","S3","storage","download","blob"]} |
| auto_load_when | Implementing file upload/download or storage |
| agent | architect |
| tools | ["Read","Write","Bash"] |
Focus: Upload, storage, CDN, processing
When to use local storage:
├── Development only
├── Single server, no scaling
└── Small files, low traffic
When to use object storage:
├── Production (S3, GCS, Blob)
├── Any production workload
├── Built-in redundancy, CDN integration
└── Scale infinitely
Storage selection:
├── S3/GCS/Blob → Most cases, production
├── Local → Dev only, never prod
├── Database (BLOB) → Small files, rare access
└── CDN origin → Large media, high traffic
Upload approaches:
├── Direct upload (client → storage)
&& Best for large files
&& Server doesn't bottleneck
&& Presigned URLs
│
├── Proxy upload (client → server → storage)
&& Validate before storage
&& Transform/process
&& Easier to control
│
└── Form upload
&& Simple
|| File goes through server
|| Not for large files
When to use each:
├── Large files → Direct (presigned URL)
├── Small files, validation needed → Proxy
├── Very simple → Form upload
└── Mobile → Direct (bandwidth)
When to process files:
├── Immediate (synchronous)
&& Small files
&& Fast processing
&& User waits for result
│
├── Background (asynchronous)
&& Large files
&& Slow processing
&& User notified when done
│
└── On-demand (lazy)
&& Process when accessed
&& Save storage
&& First access slower
Processing location:
├── Before storage → Virus scan, validate
├── At access → Resize images, generate thumbnails
└── Background → Transcode video, OCR
When to use CDN:
├── Static assets (images, videos, documents)
├── Global users
└── High traffic, reduce origin load
When NOT to use CDN:
├── Dynamic content
├── Real-time data
└── Very low traffic
CDN patterns:
├── Cache everything public
├── Invalidate on updates
├── Signed URLs for private
└── Regional edges for global
What to validate:
├── Type
&& Check MIME type, not extension
&& Use magic numbers
│
├── Size
&& Max file size limit
&& Min size (prevent empty)
│
├── Content
&& Virus/malware scan
&& Image validity
|| Document structure
│
└── Name
&& Sanitize characters
&& Limit length
|| Avoid path traversal
When to clean up:
├── Failed uploads → Immediate
├── Expired documents → Scheduled
├── Old versions → Policy-based
└── User deletion → Immediate
Cleanup methods:
├── Immediate: on failed upload
├── Scheduled: nightly/weekend job
├── Policy: TTL-based cleanup
└── Manual: user-triggered delete
❌ Reading entire large file into memory (fs.readFileSync)
✅ Stream large files: createReadStream + pipe
❌ User-controlled file paths without sanitization (path traversal)
✅ path.basename() + restrict to allowed directory
❌ Storing uploaded files on server disk (ephemeral in serverless)
✅ Stream directly to S3 / object storage
❌ No file type validation (accept any extension)
✅ Check magic bytes (file-type library), not just extension
❌ Synchronous file operations in hot paths
✅ Always async: fs.promises / streams in API handlers
| Scenario | API | Note |
|---|---|---|
| Read small file | fs.promises.readFile | Await |
| Read large file | fs.createReadStream | Streaming |
| Write atomically | write to tmp then rename | Prevents corruption |
| Upload to S3 | @aws-sdk/lib-storage | Multipart auto |
| Temp file | tmp / os.tmpdir | Clean up on close |
| Watch file | fs.watch / chokidar | chokidar more reliable |