Skill站外收录 @skilllib/skill-2014279415792873474
skill
提供跨多种存储后端的统一文件操作能力,支持本地文件系统、S3/OSS 兼容对象存储、SFTP、WebDAV、HTTP、HDFS 及标准输入输出,涵盖读写、元数据查询、目录遍历、通配匹配、数据同步与缓存等全生命周期管理。
软件开发 AI 技能
Skills.MD
# Megfile
## Overview
Guide to using megfile’s unified APIs, SmartPath, configuration, and CLI for file operations across various backends, like local FS, S3/OSS-compatible object storage, SFTP, WebDAV, HTTP, HDFS, and stdio.
## Quick Start
- Install base: `pip install megfile`; add extras per backend (`megfile[cli]`, `megfile[hdfs]`, `megfile[webdav]`).
- Configure credentials/endpoints (env vars > config files). S3 examples: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, optional `AWS_ENDPOINT_URL` / `OSS_ENDPOINT` / `AWS_ENDPOINT_URL_S3`, `AWS_S3_ADDRESSING_STYLE`.
- Path format: `protocol://bucket/key` or alias (e.g., `tos://`); bare POSIX paths are treated as `file://`.
- Import functional APIs (`from megfile import smart_open, smart_sync, ...`) or SmartPath (`from megfile.smart_path import SmartPath`).
## Supported Protocols & Extras
- Local FS (`file://` or bare paths) — base install.
- S3/OSS-compatible (`s3://`, plus aliases) — base install.
- SFTP (`sftp://`) — install `megfile[cli]` or `megfile` with SFTP deps.
- HTTP/HTTPS (`http://`, `https://`) — base install.
- Stdio (`stdio://`) — base install.
- HDFS (`hdfs://`) — install `megfile[hdfs]`.
- WebDAV (`webdav://`) — install `megfile[webdav]`.
- Full Protocol path format reference: `references/path_format.md`.
## Core Tasks
### File IO
- `smart_open(path, mode='r', encoding=None, **options)`: open binary/text handles.
- Convenience loaders/savers: `smart_load_content` / `smart_save_content` (bytes), `smart_load_text` / `smart_save_text` (str), `smart_save_as(file_obj, path)`, `smart_load_from(path)` returns BinaryIO.
- `smart_combine_open(glob, mode='rb', open_func=smart_open)`: sequentially reads multiple files as one stream.
### Existence & Metadata
- `smart_exists`, `smart_isfile`, `smart_isdir`, `smart_islink`, `smart_isabs`.
- `smart_access(path, mode=Access.READ/WRITE)`.
- `smart_stat` / `smart_lstat` (via SmartPath), `smart_getsize`, `smart_getmtime`, `smart_getmd5(recalculate=False, followlinks=False)`.
### Listing & Globbing
- Directory traversal: `smart_listdir`, `smart_scandir`, `smart_walk`, `smart_scan`, `smart_scan_stat` (returns FileEntry/StatResult).
- Pattern matching: `smart_glob`, `smart_iglob`, `smart_glob_stat` for stat-rich globbing.
### Data Transfer & Lifecycle
- Copy/sync: `smart_copy`, `smart_sync`, `smart_sync_with_progress` (progress-friendly wrapper), `smart_concat` to merge multiple sources.
- Moves/deletes: `smart_move`, `smart_rename`, `smart_remove`, `smart_unlink`, `smart_touch`, `smart_makedirs`.
- Links: `smart_symlink`, `smart_readlink`.
### Path Utilities
- `smart_path_join`, `smart_abspath`, `smart_realpath`, `smart_relpath`, `smart_isabs`.
- SmartPath mirrors pathlib semantics but routes to the right backend: `path = SmartPath("s3://bucket/key"); path.exists(); path.open(mode="rb")`.
### Caching
- `smart_cache(path, cacher=SmartCacher, **options)`: cache remote resources locally for tools that only support local files.
## Configuration
- Use CLI helpers to persist credentials/endpoints; environment variables take precedence.
- Profiles enable multiple endpoints (e.g., `s3+prod://...`). See `references/configuration/` for protocol-specific flags and env vars.
- Full config reference: `references/configuration/`.
## CLI Essentials
- Install CLI extras: `pip install 'megfile[cli]'`.
- Common commands (ls/cp/sync/stat/md5sum/mkdir/rm/touch) mirror POSIX semantics across backends.
- Completion scripts: `megfile completion zsh`.
- Full command list and flags: `references/cli.md`.
## Usage Notes
- Prefer smart_* for protocol-agnostic code paths; avoid branching per backend.
- Ensure required extras are installed for target protocols before invoking APIs.
- For high-volume sync/copy, supply `map_func` (e.g., `ThreadPoolExecutor.map`) and `callback` to report progress.
- Use aliases via `megfile config alias <alias> <protocol>` to shorten paths (e.g., `tos://`).
## References
- API surface: `references/megfile.smart.md` and `references/megfile.smart_path.md`.
- Configuration flags, env vars, and profiles: `references/configuration/`
- CLI commands and flags: `references/cli.md`
- Full Protocol path format reference: `references/path_format.md`.
- Glob patterns reference: `references/advanced/glob.md`.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「skill」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次