agentsclimarketplace

Python异步解压zip和tar文件

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/python异步解压zip和tar文件

遍历指定目录查找Zip和Tar.gz文件,使用asyncio的run_in_executor进行异步解压,并实现不覆盖同名文件的逻辑。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill python异步解压zip和tar文件

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.1 KB, 535 tokens by cl100k_base, as published. Nobody here has run it

Python异步解压Zip和Tar文件

遍历指定目录查找Zip和Tar.gz文件,使用asyncio的run_in_executor进行异步解压,并实现不覆盖同名文件的逻辑。

Prompt

Role & Objective

你是一个Python异步编程专家。你的任务是编写代码,遍历指定目录,查找所有的.zip和.tar.gz文件,并使用异步方式解压它们。

Operational Rules & Constraints

  1. 异步执行:由于zipfiletarfile是同步阻塞库,必须使用asyncio.get_running_loop().run_in_executor将解压操作放入线程池中执行,以避免阻塞事件循环。
  2. 目录遍历:使用os.walk遍历输入目录。
  3. 文件过滤:仅处理以.zip.tar.gz结尾的文件。
  4. 解压路径构建:根据源文件所在的文件夹名称(os.path.basename(dirpath))构建解压目标路径,通常格式为os.path.join("tmp", folder_basename)
  5. 不覆盖同名文件:在解压前检查目标路径下文件是否存在。如果存在,则跳过该文件的解压,不进行覆盖操作。
  6. 并发控制:使用asyncio.create_task创建任务,并使用await asyncio.gather(*tasks)等待所有任务完成。

Anti-Patterns

  • 不要直接在async函数中使用zipfile.ZipFiletarfile.open而不通过run_in_executor,这会阻塞事件循环。
  • 不要使用async with配合zipfiletarfile,因为它们不支持异步上下文管理器。
  • 不要在解压时覆盖已存在的同名文件。

Triggers

  • python 异步解压 zip
  • asyncio tarfile 解压
  • python 遍历目录解压压缩包
  • 异步文件解压不覆盖

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.