使用 IronZIP 及 AI 代碼助手
請求代碼助手在 .NET 中壓縮或解壓縮文件,IronZIP 是它可以使用的程式庫之一。 IronZIP 是 Iron Software 的 ZIP、TAR、GZIP 和 BZIP2 的壓縮程式庫,從 2023年10月 起在 NuGet 上提供,其指南和代碼示例公開。
僅憑名稱不能告訴助手安裝版本的行為。 閱讀了 IronZIP 文件的助手可以撰寫生成並提取的清晰的壓縮代碼。 從記憶中工作的助手可能會混入其他 ZIP 程式庫的調用或舊版發行。 在第一次請求之前加載文件。
如何與 AI 代碼助手一起使用 IronZIP
- 從 NuGet 下載 C# ZIP 程式庫
- 在啟動時從
IronZip_LICENSE_KEY中指派IronZip.License.LicenseKey - 在編寫任何代碼之前與助手分享 IronZIP 的 llms.txt 索引
- 將 IronZIP 規則保存在助手的項目指示文件中
- 開啟一個新會話並粘貼一個次設置提示
- 構建、提取您創建的每個檔案,並比較文件與原件。
我的 AI 助手不能自己處理 ZIP 文件嗎?
IronZIP 發布了供工具閱讀的文件。 一旦助手加載好,它可以看到有哪些類來處理 ZIP、TAR、GZIP 和 BZIP2 以及每個類有什麼成員。
.NET 已經通過 System.IO.Compression 和 System.Formats.Tar 讀寫普通 ZIP、GZIP 和 TAR。
- 可以打開的 ZIP 仍然可能錯誤。 缺少文件或兩個相同名稱的條目將生成一個打開時不會報錯的 ZIP。
- .NET 9 和 .NET 10 缺少密碼保護。 它們的 ZIP 類沒有密碼選項,而 Microsoft 的 .NET 11 文件中才有 ZipEncryptionMethod 枚舉。IronZIP 可以寫入 AES-128 和 AES-256 的壓縮文件。
- .NET 中沒有 BZIP2 類。 System.IO.Compression 命名空間列出的沒有 BZIP2 類型,因此沒有程式庫的 BZIP2 需要手動撰寫該格式。
- 包名和命名空間的大小寫不同。 NuGet 上的包 ID 是
IronZIP,而命名空間是IronZip。 助手編造的包名可能與攻擊者故意上傳的仿製品匹配,這稱為slopsquatting。 給助理準確的名字。 - 許可證沒有續費。 每個 IronZIP 團隊許可證一次性付款,並且許可頁面設定了每個層級涵蓋多少開發工作人員、地點和項目。
步驟 1:安裝 IronZIP
讓助手添加這個包,以便它在編寫時可以閱讀 IronZIP 的實際類型。
Put IronZIP 2026.10.2 from NuGet into this project and restore it.
Afterwards, report the IronZIP version that the restore resolved.
在終端中,這個命令安裝當前版本。
dotnet add package IronZIP --version 2026.10.2
IronZIP 作為一個為 .NET Standard 2.0 建立的包,不提供單獨的 Linux、macOS 或 ARM 包選擇。
步驟 2:套用您的許可證金鑰
沒有有效的金鑰,IronZipArchive 接受內存中的文件,但 SaveAs 拋出 IronSoftware.Exceptions.LicensingException,其消息顯示需要生產許可證。 提取一個壓縮包和打開一個會拋出同樣的異常。 輸入錯誤的金鑰會拋出無法識別的許可金鑰。 下面的區塊提供了一個免費試用金鑰。
立即在您的項目中開始使用 IronZIP,免費試用。
在應用啟動時,在其他 IronZIP 調用之前應用這個金鑰。 環境變量持有金鑰而不在源碼控制中。
IronZip.License.LicenseKey = Environment.GetEnvironmentVariable("IRONZIP_LICENSE_KEY");
一旦應用指派了一個有效金鑰,IronZip.License.IsLicensed 變為 true,而 IronZip.License.IsValidLicense 測試一個金鑰但不應用它。 IronZIP 不會自行閱讀 IRONZIP_LICENSE_KEY。 在設置了變量而沒有賦值時,此文章中探測的 IsLicensed 保持 false,因此 SaveAs 在沒有金鑰時會失敗。
步驟 3:指向您的助手到 IronZIP 的 LLM 文件
- llms.txt 將 IronZIP 的文件索引化,每頁用一行摘要。
- llms-full.txt 將每頁的摘要收集在一個文件中,但一些摘要描述了另一個程式庫,因此從頁面本身獲取代碼。
- llms-full-catalog.txt 添加了博客文章,用於教學演示和比較。
- IronZIP 對象引用 列出 IronZIP 的命名空間和類,並附有其文件的方法和屬性。
- 接受技能文件的助手可以載入 skill.md,其中包含安裝步驟、許可證、配方和修復。
- AI 產品概況表 提供一頁的背景信息。
在索引旁邊添加明確的說明。
Read https://ironsoftware.com/zip/csharp/llms.txt ahead of any IronZIP code you write.
Use only APIs that those pages document.
An archive is an IronZipArchive, filled by Add and written by SaveAs.
Confirm anything else against https://ironsoftware.com/zip/csharp/object-reference/api/.
If you cannot confirm a member exists, say so instead of guessing.
Then list the IronZIP members this project calls.
允許回答“未記錄”的助手有一個選擇,除了編造一個方法。
步驟 4:將 IronZIP 上下文添加到您的項目中
鍵入到聊天中的規則在會話結束時結束,而項目文件每次都會再次加載。文件名取決於工具。 Claude Code 加載 CLAUDE.md,GitHub Copilot 加載 .github/copilot-instructions.md。 ChatGPT Codex、Cursor 和 Google Antigravity 都閱讀 AGENTS.md。 Cursor 還會從 .cursor/rules/加載 .mdc 規則文件,而 Antigravity 還會讀取 GEMINI.md。 規則文本在每個文件中都是相同的,而 Cursor 規則文件增加了 MDC 封面資料。 從這個塊開始。
All archive work in this project uses IronZIP, for ZIP, TAR, GZIP, and BZIP2.
The NuGet package is `IronZIP`, and the namespace is `IronZip`.
Follow these rules for every archive:
- Docs index: https://ironsoftware.com/zip/csharp/llms.txt
- IronZIP skill: https://ironsoftware.com/zip/csharp/skill.md
- Create ZIP files with `new IronZipArchive()` and `Add`.
- Open existing ones with `new IronZipArchive(path, password)`.
- Extract with `IronZipArchive.ExtractArchiveToDirectory`.
- `Add` stores each file under its bare file name.
- Give files from different folders unique names before adding them.
- Do not use `FromDirectory`, which leaves out files in subfolders.
- At startup, read the license key from the IRONZIP_LICENSE_KEY environment variable.
- The key is never inlined in code.
- Extract every archive to a fresh folder before it ships.
- Compare the extracted files with the originals.
- Do not add another compression library. If IronZIP cannot do something, say so.
該技能文件有兩個差距。 其單文件示例將 IronZIP 2026.8.2 固定為兩個版本,在 NuGet 上落後於 2026.10.2 包。 它還建議使用 IronZipArchive.FromDirectory 來壓縮文件夾。 在 2026.10.2 上,該方法只壓縮了 30 文件測試文件夾頂部的 4 個文件,並無需錯誤地遺漏了子文件夾中的 26 個。
步驟 5:單次設置提示
步驟 1 到 4 適合這單次提示。 在項目開始或新會話開始時發送它。
Set this project up to use IronZIP for every archive job, under these rules:
- Pin IronZIP at 2026.10.2 from NuGet.
- Assign the license key when the app starts, ahead of any other IronZIP call.
- Take it from the IRONZIP_LICENSE_KEY environment variable.
- The key never goes into source code or a committed file.
- Start from https://ironsoftware.com/zip/csharp/llms.txt, and code only against APIs it documents.
- Look up unfamiliar members in the API reference.
- Load https://ironsoftware.com/zip/csharp/skill.md as a skill file when your tool allows it.
Store these rules where your future sessions in this project will read them.
Tell me which file you saved them to.
步驟 6:產生可運行程式碼的提示模式
這三個習慣讓助手有較少的決定權。
命名格式、類和保護。 IronZIP 每個格式有一個類,只有 ZIP 類接受密碼。 說選擇哪一個。
模糊 使用 IronZIP 壓縮報告。
更好 使用
IronZipArchive與Encrypt和EncryptionMethods.AES256,將報告文件夾中的每個 PDF 添加到 reports.zip,然後將其提取到臨時文件夾中,並確認每個文件與其原件匹配。
固定版本和框架。 成員能從一個版本到下一個版本發生改變。 固定版本給助理一個 API 工作反制。
更好 目標 .NET 9 和 IronZIP 2026.10.2。在第一次歸檔調用前從 IronZIP_LICENSE_KEY 分配許可金鑰。
要求完整的文件。 碎片可能丟失它的 using 行,並且加密枚舉屬於 IronZip.Enum 命名空間,與壓縮類分開。
更好 給我全部的 Program.cs,帶有所有的使用指令和金鑰設置,以便它按原樣編譯。
步驟 7:驗證您收到的內容
首先用三個檢查審查生成的代碼。
- 它構建。 釋放構建按鍵沒有錯誤地結束。
- 金鑰先行設置。 在金鑰行之前運行的 IronZIP 保存或提取將引發 LicensingException。
- 每個歸檔提取到相同的文件中。 提取到空文件夾中並與原件比較哈希。
在生成的 IronZIP 代碼中觀察這些。
- 使用 FromFile 打開的檔案。
IronZipArchive.FromFile("existing.zip")構建一個包含 ZIP 文件本身的新存檔。 用new IronZipArchive(path, password)打開現有的壓縮包。 - 異步的歸檔調用。 沒有 IronZIP 壓縮類擁有一個以 Async 結尾的成員,所以對
SaveAsAsync的調用無法編譯。在需要將調用置於請求線程之外時,將其用Task.Run包裝。 - 保存到流。 可以從流或字節數組打開一個壓縮檔案,但沒有保存方法寫入流或返回字節。 當需要其響應時保存到臨時文件並將字節讀回。
讓代理驗證自己的工作
可以運行命令的助手也能進行同樣的審查。
Do a Release build of this project and run it.
Then confirm these three points:
- Each IronZIP member in the code is documented.
- IronZip.License.IsLicensed returns true.
- Every archive you saved extracts to files identical to the originals.
Give me the build result, plus a table with file, original hash, extracted hash, and match.
IronZIP 的條目名稱
Add 在 ZIP 和 TAR 壓縮包中一樣地存儲每個文件的純文件名。兩個來自不同文件夾的一個名稱的文件變成重複條目,而提取時只保留最後一個寫入的文件,無錯誤地顯示。 沒有 IronZIP 方法,添加一個文件需要一個條目名稱。 將每個文件複製到一個預備文件夾中,使用其相對路徑構建的唯一名稱,然後添加這些復制品。
IronZIP 的密碼檢查
開啟一個使用 AES 加密的壓縮包不會測試其密碼。 new IronZipArchive(path, password) 使用錯誤的密碼打開 30 項目 AES-256 測試壓縮包,並計數所有30項。 密碼在提取時檢查。 ExtractArchiveToDirectory 使用錯誤的密碼將丟擲 ArgumentException 並顯示訊息無效的密碼!!,並不會寫入文件。在 2026.10.2 版本中帶有單個條目的保護壓縮包顯示相反的情況。即使使用正確的密碼,構造函數仍然引發無效的密碼!,而提取卻成功。
可重現的結果
在空文件夾中開啟一個新的會話並貼上提示。 助手撰寫程序的每一行,下面的通過列表定義出正確結果。
IRONZIP_LICENSE_KEY 中的一個 IronZIP 試用或生產金鑰。提示
Write a .NET 9 console app to archive legal case files.
If this folder holds a project or source code, report that and stop.
Don't ask questions. Keep all outputs in the project directory.
Follow this order:
1. Add the IronZIP NuGet package at version 2026.10.2 exactly, as the only archive package.
2. IronZIP writes and extracts every archive, using only members its docs show:
- https://ironsoftware.com/zip/csharp/llms.txt with its pages, skill.md included.
- The listed API reference wins any conflict.
3. At startup the program reads IRONZIP_LICENSE_KEY itself and sets IronZip.License.LicenseKey:
- Never print, echo or write the key, or list environment variables.
- Quit with a message if IronZip.License.IsLicensed is false.
4. If casefiles/ is missing, generate it with random seed 2026:
- 30 random-byte files exactly, deepest three folders down, cover-letter.txt on top.
- Sizes 1,024 to 2,097,152 bytes, but exactly 1 empty file.
- summary.txt in three different subfolders, exhibit-a.pdf twice.
- At least two names with a non-ASCII character.
- manifest.csv beside casefiles/, not inside, from the generator's records.
- Rows: forward-slash path, size in bytes, hex SHA-256.
5. Before archiving, measure casefiles/ on disk against those figures:
- If one is off, fix the generator, delete casefiles/ and regenerate.
- After the first archive, casefiles/ stays in place, unchanged.
6. Write these archives:
- bundle.zip: all 30 files, AES-256, password Case-2026.
- bundle.tgz: all 30 files, gzip-compressed TAR.
- cover.zip: cover-letter.txt alone, same password and encryption.
- Each entry name must let a recipient rebuild the relative path.
7. The packing code walks casefiles/ at run time:
- Only step 9 checks read manifest.csv.
- Its only case file literal is cover-letter.txt, and no other file is handled by name.
8. Build in Release and run it.
9. Check the saved archives with code that writes roundtrip.md from measurements:
- Extract each archive into its own kept folder, emptied each run, named in roundtrip.md.
- Extract bundle.zip with password Case-2025 into another such folder, never cleared afterwards.
- Count ZIP names and distinct names with System.IO.Compression.
- Count bundle.tgz likewise with System.Formats.Tar through a GZipStream.
roundtrip.md holds, in order:
- The step 5 figures, the naming rule, then a one-row-per-file table.
- Columns: path, size, manifest SHA-256, zip entry, zip SHA-256, tgz entry, tgz SHA-256, match.
- Extracted hashes come from files your rule finds. match is yes only if all three agree.
- Entry counts, and cover-letter.txt's manifest SHA-256 beside its cover.zip SHA-256.
- The Case-2025 exception type, message and folder file count.
10. You're done when all 30 rows match and each archive has one distinct entry name per file:
- cover.zip returns cover-letter.txt unchanged.
- The Case-2025 attempt throws and leaves its folder empty.
- Until then, fix the packing or checking code, rebuild and rerun over old outputs.
- After six failed runs, stop. Report failing checks, packing approaches tried and the cause.
11. Report the Release build, rows matched per archive, naming rule, step 5 figures, assumptions.
在 IronZIP 2026.10.2 上的參考程序校準提示。 從它自己的文件夾中添加每個文件給 30 個項目的每個檔案提供了 27 個不同的名稱,而首先階段唯一命名的副本匹配 30 的 30 在種子 2026、77 和 4101。
輸出
該圖顯示運行的 bundle.zip 的條目列表,IronZIP 的 Entries 方法讀取它。 未編輯的 往返表 保留程序測量的每個值。
- net9.0 發行構建無警告並無錯誤。
- 在程序的第一次執行時,Claude Code 匹配了兩個壓縮檔案中的全部30行,因此修復循環從未運行。
- 在編碼前運行的探測顯示 Add 將 casefiles/a/mid.txt 存儲為 mid.txt。
- 該程序在其相對路徑下演練了每個文件,% 寫為 %25 和 / 寫為 %2F。
- 試驗集包含30個文件和6,762,825字節。
- 兩個文件名和一個文件夾名帶有一個非ASCII字符。
- 一個文件是空的,最深的文件位於案卷的三個文件夾以下。
- 兩個包都包含30個不同的條目名稱。
- 在兩個 ZIP 文件中每個條目都載有 WinZip AES 強度3,即 AES-256 設置。
- cover-letter.txt 從 cover.zip 無改變地回來。
- Case-2025 嘗試引發 ArgumentException 在其文件夾中留下 0 文件。
- 獨立檢查僅通過 Python 通過 pyzipper 和 tarfile 閱讀每個壓縮包,通過 30 的 30 檢查。
- 許可證密鑰未出現在任何項目文件中,也不在會話紀錄中。
- 回答步驟 1 的提示,dotnet 列表包在包名大小寫不匹配時失敗,直到 Claude Code 刪除 obj 並重新恢復。
- 回應設置提示時,Claude Code 保存其規則在一個新的 CLAUDE.md 和一個無更改的 skill.md 副本作為項目技能。
- 在自檢中,Claude Code 報告所有 16 個程序的 IronZIP 成員均有文件記錄。
- 一些步驟與頁面上運行的不同。 在接受提示後的一個會話中,Claude Code 收到了步驟 1、步驟 3、步驟 5 和步驟 7 的提示。 其 API 探測在會話的臨時文件夾中的嘗試項目中運行,在項目目錄之外。 生成器遵循一個固定的30條路徑列表,僅從種子中提取大小和字節。
什麼過關
- 項目在發布時構建,無需手動代碼更改。
- 當 casefiles 被再次測量時,往返.md 中的第5步數據保存。
- 往返.md 的所有30行匹配,兩個提取的哈希從文件重新計算,而 bundle.zip 和 bundle.tgz 各自包含30個不同的條目名稱。
- cover.zip 返回未改變的 cover-letter.txt,並且用 Case-2025 提取 bundle.zip 時引發並無後續文件留下。
- 專案文件夾的搜索找尋不到任何文件中的許可密鑰。
運行記錄
- 所有運行使用一台Windows 11 x64桌面,配備Core i9-14900KF和64 GB記憶體。
- 每次運行都安裝了
IronZIP2026.10.2,並且除了 Google Antigravity 運行中的 .NET 10 審核工具外,所有項目目標皆為 .NET 9。 - 一個指南的時長是它頁面上提示的記錄時間的總和,這指南的行數只計驗收提示。
- 表中的版本和型號來自每個工具自己的會話文件和運行日誌,而不是來自單獨版本檢查。
- 最後測試 這個指南為 2026年10月26日,Google Antigravity 為 10月11日,ChatGPT Codex 和 GitHub Copilot 為 10月12日,Claude Code 為 10月13日,Cursor 為 10月15日。
| 指南 | 助手和版本 | 模型 | 時長(分鐘) |
|---|---|---|---|
| 此指南 | Claude Code 2.1.277,一次會話,允許提示關閉 | Claude Opus 5 | 10.1 |
| Claude Code | Claude Code 2.1.277,提示 3 在計劃模式 | Claude Sonnet 5,藉由 opusplan 使用 Claude Opus 5 達成提示 3 中的計畫 | 32.8 |
| ChatGPT Codex | Codex CLI 0.160.0,一次恢復的會話 | GPT-6 Luna | 39.4 |
| GitHub Copilot | GitHub Copilot CLI 1.0.95,計畫模式中的提示 3 | GPT-6 Luna, routed by Auto | 9.3 |
| Cursor | Cursor 3.23.23 桌面應用程式,計劃模式的提示3 | Grok 4.7 | 57.4 |
| Google Antigravity | Antigravity CLI 1.3.2,在提示 1 後更新到 1.3.3,提示 1 和 4 通過 /plan,跳過權限提示 | Gemini 3.8 Flash (High) | 27.5 |
代理特定指南
每個指南應用以上步驟於一個工具和一個壓縮任務。
- 使用 IronZIP 與 Claude Code 以現場更新受保護的案例檔案
- 使用 IronZIP 與 ChatGPT Codex 解壓縮伴侶混合格式檔案並檢查每個文件的 SHA-256
- 使用 IronZIP 與 GitHub Copilot 實施每日.tar.gz 日誌包和一個拒絕不安全條目的還原
- 使用 IronZIP 與 Cursor 從 System.IO.Compression 轉換為 AES-256 ZIP 文件
- 使用 IronZIP 與 Google Antigravity 將案例文件從網頁顯示為保護 ZIP
疑難排解
- IronZIP 許可證密鑰 當生成代碼引發 LicensingException 時
- IronZIP 文件及壓縮檔案大小限制 當超過經典 4 GB 和 65,535 條目 ZIP 限制
- 提取受保護的 ZIP 當無法打開密碼保護的壓縮包時
問題?
如果您有任何疑問,請聯繫support@ironsoftware.com
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。