如何使用IronZIP與Google Antigravity

Curtis Chau
Curtis Chau
已更新: 2026年10月26日

一個將客戶案例文件提供為密碼保護的ZIP頁面可以乾淨地編譯,但仍可能傳送缺少檔案的檔案,有關普通案件的錯誤頁面,或不同案件的文件。

Google Antigravity 的 /browser 命令會啟動一個 Chrome 瀏覽器子代理,可以操作運行中的頁面,因此一個提示可以輸入密碼、按下下載以進行每個測試案例,並保留每個結果的截圖。 IronZIP在服務器上使用AES-256加密構建存檔並重新提取,因此頁面可以證明每個文件都逐字節返回。 本指南從IronZIP的密碼保護範例開始,在ASP.NET Core MVC應用程式中構建該下載頁面,並檢查五個案件,其文件和SHA-256哈希值已事先知道。

快速開始
NuGet使用NuGet安裝

PM > Install-Package IronZip

在 NuGet 包管理器控制台中運行上述命令安裝 IronZIP,或在 NuGet 包管理器中搜索該包。

打開Antigravity中的CaseDocs資料夾並描述下載頁面。

/plan CaseDocs is an ASP.NET Core MVC project that targets .NET 9.
Add the case document download that docs/case-download-rules.md describes.

The download works like this:

- A user opens /Cases/{id}, ticks documents and types a password.
- The user receives an AES-256 encrypted ZIP that the server builds with IronZIP.
- The NuGet package is IronZIP version 2026.10.2, and its namespace is IronZip.

Program.cs reads IRONZIP_LICENSE_KEY and assigns it once to IronZip.License.LicenseKey.
Confirm only that the variable exists and how many characters it holds.
Never print, log or write its value.

The Implementation Plan must state these answers:

- the entry name each document receives inside the archive
- the path the archive is saved to before the response, and when that file is deleted
- how the saved archive is compared with the ticked documents

Stop once dotnet build succeeds, and tell me the build result.
Text

在代碼更改之前閱讀這三個答案。 每項涵蓋了檔案可能出錯的一種方式,而沒有編譯器錯誤。 在headless agy -p中沒有人批准計劃,因此閱讀它所描述的計劃工件。

在提示中命名變量,且永遠不要粘貼值。 對話中輸入的任何內容都可以到達源文件、提交或終端紀錄。 IronZIP還接受appsettings.json中的IronZip.LicenseKey項目,提交包括該文件和所有其他內容。 所有支援的位置都在授權金鑰指南中。



在接受更改之前您應該檢查什麼?

檢查每個條目名稱的來源,每個存檔儲存的資料夾,刪除它的行,和讀取存檔的代碼。 然後在不同中確認每個IronZIP成員與API參考。

Antigravity將截圖保存為圖像工件,接受評論。 當顯示錯誤頁面或文件數量錯誤時,對該截圖評論,而不是寫新的提示。

您如何在真正的瀏覽器中測試每個下載?

請求只有實際下載才能填寫的結果表。

/browser Start CaseDocs in the background with dotnet run --launch-profile http.
That profile listens on http://localhost:5065.

For each row of TestData/expected.csv, do this:

1. Open /Cases/<case> and leave every checkbox as the page sets it.
2. Type the row's password and press Download.
3. Capture a screenshot of what follows.
4. When the answer is a file, take its name and size from the download or the response headers.

In the Walkthrough and in your reply, give one line per row with these parts:

- the case
- the documents the page listed, against the documents column
- the expected outcome
- what actually happened, as the file name and size or the message shown
- a PASS or FAIL verdict

For any failing row, cite the server log entry or error page text responsible.
Do that before you edit any code.
After every fix, restart the app and go through all six rows again.
Stop the app when you are done.
Text

對條目名稱的修復會更改每個存檔,即使是已通過的案例,這就是促使重新運行所有六行的原因。

請注意: 首先打開單文件案例的截圖。通過其他案例的頁面還可以在這裡返回錯誤頁面。

什麼導致不完整或失敗的下載?

在我們的校準中,從密碼保護範例轉移到下載動作中的代碼。 它切換到AES-256並通過構造函數打開保存的存檔來計算條目。 Headless Chrome然後在每個案例上按下下載,使用IronZIP 2026.10.2。以下每次失敗都無警告編譯。

發生了什麼原因需要詢問什麼
六文件案例下載完成,但提取時只返回3個文件IronZIP只根據檔案命名每個條目,所以兩個letter.pdf、兩個scan.jpg和兩個summary.pdf文件共享相同名稱條目名稱從相對路徑生成,並在使用這些名稱保存的副本下保存
單文檔案例返回錯誤頁面構造函數讀入時用正確密碼拋出"無效密碼!"一個讀取提取存檔
空案件返回錯誤頁面保存無條目的存檔拋出"現有的存檔已損壞!"IronZIP運行之前的選擇檢查
一個復選框值編輯為../C-1001/ledger.csv,把另一個案件的文件放入下載中動作信任發佈的路徑每個發佈的路徑解決並保持在案例資料夾內
四個ZIP文件保留在臨時資料夾中IronZIP僅保存到路徑,並且沒有刪除文件每次請求一個資料夾,請求結束時刪除

六文件案例的條目計數檢查通過,因為存檔包含六個條目。

如何設置一個Antigravity可以工作的專案?

代理需要一個已經在localhost上構建和回答的應用程式。dotnet new mvc --framework net9.0給您一個,並且運行一次後在Properties/launchSettings.json中顯示端口。 端口因專案而異,/browser必須命名它。 瀏覽器的允許列表最初只保存localhost,因此在http://localhost:<port>表單中保留地址。

提交案卷資料夾到CaseFiles下,規則在docs/case-download-rules.md中,TestData/expected.csv中包含每個案例和密碼的結果,以及TestData/manifest.csv中每個文件的條目名稱、大小和SHA-256。五個測試案例中有五個普通文件,六個文件具有三個名字在子資料夾中重複,一張聲明,三個文件具有帶重音和日文名稱,沒有文件。 然後讓代理審核包和金鑰。

Which IronZIP version does CaseDocs.csproj reference? Quote its PackageReference line.
Then show the line in Program.cs that assigns the license key.
Add either line if it is missing.

IRONZIP_LICENSE_KEY is the only allowed source of that key.
Search these files for an IronZip.LicenseKey entry or a key value, and remove any you find:

- appsettings.json
- appsettings.Development.json
- Properties/launchSettings.json

When the variable is missing at startup, the app logs a single warning.
That warning mentions IRONZIP_LICENSE_KEY and contains no value.
Add it only if it is absent, and leave every other file alone.
Tell me what you found and what you changed.
Text

只要後面的提示添加專案或包,重複該版本號,使每個專案都與相同的IronZIP版本一起構建。 從記憶中寫包名的代理可以安裝一個以幻想名稱發布的惡意包,一種攻擊稱為爛名佔領。 包名是IronZIP,命名空間是IronZip。

設置變量並且License.LicenseKey從未分配,校準頁面在保存呼叫時對所有四個存檔案例均失敗。 每次拋出LicensingException,讀入"需要生產許可"。 IronZIP不會自動讀取IRONZIP_LICENSE_KEY,所以應用程式必須自己分配IronZip.License.LicenseKey。 有關IronZIP代理文件和單提示接受測試,請參見AI編碼助手指南。

服務應如何將文件傳遞給IronZIP?

Add,AddArchiveEntry和FromFiles 都將資料夾丟在探測中,即使是相對路徑如2025/letter.pdf,提取保留兩個同名條目中的後一個。 添加資料夾路徑拋出UnauthorizedAccessException。 因此,服務將每個文件複製到給定名稱下的臨時資料夾中,並添加副本。

構造函數失敗涵蓋了開啟單條目AES-256存檔的所有方式,因為流、字節陣列和FromArchive方法重載拋出了相同的System.Exception。 對於兩個或兩個以上的AES-256條目,構造函數列出了它們即使密碼錯誤,而傳統存檔在構造函數中拋出ZipException。 提取返回單條目存檔完整並拋出ArgumentException,對於每個錯誤、空或缺失的密碼拋出"無效密碼!"

在IronZIP 2026.10.2中,ZIP壓縮等級沒有影響。等級0, 1, 6和9從1,042,684字節的探測文件生成了相同的970,545字節存檔,每次構建花費119到121毫秒。

/plan Draft the Implementation Plan for this change, and wait for review before you edit anything.
Move every IronZIP call out of the controller into Services/CaseArchiveBuilder.cs.
Register it in DI as a singleton.
Given the case folder, the ticked relative paths and the password, it returns the ZIP bytes.

The service works in this order:

1. It copies each document into a new folder under the system temp path.
2. Each copy gets the entry name from the rules.
3. It adds those copies and saves the archive beside that folder.
4. It extracts that archive with the same password into a second folder.
5. It compares the SHA-256 of every extracted file with its source.
6. On any difference, it throws with the document's entry name.

Both folders are removed in a finally block.
The controller keeps the password, selection and path checks.
Afterward, repeat the /browser pass over TestData/expected.csv and report each row.
Text

比較代理的服務與這個。 它用IronZIP 2026.10.2構建,並且返回所有四個存檔完好,沒有留下臨時資料夾。

using System.Security.Cryptography;
using IronZip;
using IronZip.Enum;

public sealed class CaseArchiveBuilder
{
    public byte[] Build(string caseFolder, IReadOnlyList<string> relativePaths, string password)
    {
        var work = Path.Combine(Path.GetTempPath(), "case-" + Guid.NewGuid().ToString("N"));
        var staged = Path.Combine(work, "staged");
        var check = Path.Combine(work, "check");
        Directory.CreateDirectory(staged);
        try
        {
            var sources = new Dictionary<string, string>();
            foreach (var relativePath in relativePaths)
            {
                var entryName = relativePath.Replace('/', '_');
                var source = Path.Combine(caseFolder, relativePath);
                File.Copy(source, Path.Combine(staged, entryName));
                sources.Add(entryName, source);
            }

            var zipPath = Path.Combine(work, "case.zip");
            using (var archive = new IronZipArchive())
            {
                archive.Encrypt(password, EncryptionMethods.AES256);
                foreach (var entryName in sources.Keys)
                    archive.Add(Path.Combine(staged, entryName));
                archive.SaveAs(zipPath);
            }

            IronZipArchive.ExtractArchiveToDirectory(zipPath, check, password);
            if (Directory.GetFiles(check).Length != sources.Count)
                throw new InvalidOperationException("The archive does not hold one entry per document.");
            foreach (var (entryName, source) in sources)
            {
                var extracted = Path.Combine(check, entryName);
                if (!File.Exists(extracted) ||
                    !SHA256.HashData(File.ReadAllBytes(extracted)).SequenceEqual(SHA256.HashData(File.ReadAllBytes(source))))
                    throw new InvalidOperationException($"{entryName} did not come back from the archive intact.");
            }
            return File.ReadAllBytes(zipPath);
        }
        finally
        {
            Directory.Delete(work, recursive: true);
        }
    }
}
C#

您如何證明每個存檔包含正確的文件?

/goal運行直到遍目標達成,途中不要求確認。

/goal Every archive the download page produces matches TestData/manifest.csv.

Create a console project at tools/ArchiveAudit that meets these conditions:

- It references IronZIP 2026.10.2.
- The web project's compile items exclude it.
- Its startup copies IRONZIP_LICENSE_KEY into IronZip.License.LicenseKey.

Start CaseDocs with dotnet run --launch-profile http before the first post.
Stop it once the audit passes.

For each expected.csv row with the outcome zip, the audit does this:

1. Post that case page's form with every document ticked and the row's password.
2. Store the response as audit-output/<case>.zip.
3. Extract it with IronZipArchive.ExtractArchiveToDirectory and the password.
4. Confirm that the entry names and SHA-256 values equal that case's manifest rows.

Confirm too that extraction with a wrong password throws.
Keep fixing the app and rerunning the audit until all four archives pass.
Then put the results table in the Walkthrough and in your reply.
Text

.NET自己的讀者不能進行此檢查。 System.IO.Compression 列出了校準AES-256存檔的條目名稱,但拋出了InvalidDataException,"不支持的壓縮方法",針對15個條目的內容,因此在其上構建的測試可以不讀取字節的情況下計數條目。

您如何將下載規則應用於後續任務?

根據Antigravity的規則文檔,規則來自於在從編輯的文件到工作區根目錄的每個資料夾中的AGENTS.md, GEMINI.md和.agents/rules/*.md文件。 .agents/rules中的文件必須以有效的trigger命名的YAML前置打開,丟失或無法識別的觸發器使Antigravity在沒有訊息的情況下放棄該規則。 使用model_decision,只有規則的路徑和描述進提示,而當其任務符合描述時代理載入全文。

/learn將會話中的更正轉化為規則或技能。 快捷命令頁面稱其可以寫AGENTS.md, GEMINI.md或.agents/rules中的文件,因此在提示中命名規則路徑。

/learn Turn what this session established about case downloads into a rule.
Write it at .agents/rules/case-archives.md.
Start the file with YAML frontmatter that sets trigger: model_decision.
Add a description saying the rule applies to work on case downloads or IronZIP archives.

The rule covers these points:

- how entry names are formed, and why
- how the saved archive is verified
- which temporary folders each request creates, and when they are deleted
- the messages for a short password and an empty selection
- that no change to the download is finished until two checks succeed

Those two checks are the expected.csv browser pass and the tools/ArchiveAudit run.
Record only what this session verified, and list anything unproven as open.
Text

之後,閱讀文件的前幾行並確認前置拼寫為觸發器model_decision,使用蛇形命名法。

何時啟動更多代理?

將自動化測試交給一個代理,並將瀏覽器證據交給另一個。

Split this work between Agent A and Agent B.

Agent A creates CaseDocs.Tests, an xUnit project that references IronZIP 2026.10.2.
Keep it outside the web project's build.
The tests work like this:

- They start the app with WebApplicationFactory<Program>.
- They post the download form for every expected.csv row and assert the outcome.
- For zip rows, they extract the response with IronZIP into a temporary folder.
- They compare the names and SHA-256 values with manifest.csv.
- One test shows that a path outside the case folder gets a 400 response.
- They assert on extracted files, never on archive bytes.

Agent B starts once Agent A's suite passes:

1. Start the app with dotnet run --launch-profile http (http://localhost:5065).
2. Use /browser to download C-1002 and C-1003 from their case pages, and record each session.
3. Read each file's name and size from what the browser receives or from the response headers.
4. Stop the app.
5. Add the two recordings and one screenshot per finished page to the Walkthrough.

If there is no Walkthrough, save them under audit-output/ instead.
List them with those names and sizes in your reply.
If Agent A's suite does not pass, report the failing tests instead.
Text

通過WebApplicationFactory發佈表單的測試不需要瀏覽器也不需要開放的端口,因此它們在幾秒鐘內就能捕獲破損的條目名稱。

請注意: 在桌面應用中,代理A和代理B可以以背景代理的形式單獨運行。 僅當代理A的套件首先在同一提交上通過時,才信任代理B的錄音。

在實際運行中,這些提示產生了什麼結果?

所有七個提示都在一個Antigravity CLI對話中順序運行,鍵盤無人值守,在一個新的.NET 9 MVC應用中持有五個案例、規則和兩個CSV文件。 下列數據來自我們自己的Release構建,headless Chrome下載和IronZIP提取,而不是代理的回復。

  • 在提示01之後和最終應用中,代碼在獨立的瀏覽器通過中匹配所有六個expected.csv行,並以400回應編輯的路徑。
  • 在這兩個時間點,IronZIP提取每次下載返回manifest的名稱和SHA-256值,文件為5的5, 6的6, 1的1和3的3。
  • 在這兩個時間點,錯誤密碼的提取拋出"無效密碼!"
  • 最終存檔為979,949, 779,422, 3,637和154,332字節,上述服務產生相同大小。
  • 最終下載通過未在臨時資料夾中留CaseDocs文件。
  • 應用、審核工具和測試項目的Release構建報告了0警告和0錯誤。
  • xUnit套件在2秒內通過了7的7。
  • 在寫讀入前,提示01在暫存控制台專案中測試IronZIP並遇到單條目失敗。
  • 提示01的控制器僅在標記多於一個文件時才使用構造函數打開存檔。
  • 對於單個文檔,該控制器列出了帶有System.IO.Compression的條目。
  • 提示04用提取和SHA-256比較替換了那個檢查。
  • 第一次運行目標審計通過,沒有需要修復的地方。
  • /learn寫了一個68行的規則,使用model_decision觸發器。
  • 在提示03中,代理測試了嵌套powershell -Command的缺失密鑰警告,其雙引號展開IRONZIP_LICENSE_KEY。
  • 生成的錯誤消息將密鑰值傳遞給模型並進入Antigravity的.gemini/antigravity-cli下的轉錄文件,而沒有資料夾文件持有它。
  • 一些步驟與頁面上運行的不同。 瀏覽器子代理無法連接到測試計算機上的Chrome(“找不到DevToolsActivePort”),因此代理使用自己的Playwright腳本驅動headless Chrome進行每次瀏覽器通過、截圖和錄音。 它的回覆仍然歸功於瀏覽器子代理。 提示01, 04和06各自表示它們在等待審查,然後在同一個回合中進行編輯。 CLI在整個對話中保留一個計劃和一個演練,隨後的提示覆蓋了兩者,所以只有回覆保留了之前的表格。 /learn規則表述從IronZIP反編譯得到的原因,並命名System.IO.Compression作為提取這些存檔的一種方式。 一個代理在同一個對話中在同一回合完成了兩代理提示的兩個部分。 審核工具目標.NET 10。每個權限提示都被略過了。

ChatGPT Codex指南在探險者和工作者代理之間分配存檔接收工作,其運行產生了四個代理線程。 Claude Code指南計劃進行計畫模式下的加密案例存檔的就地更新,正如這裡的/plan提示所做的那樣。 集線器的運行記錄給出Antigravity版本、模型、提示持續時間和測試機。


疑難排解


問題?

如果您有任何疑問,請聯繫support@ironsoftware.com

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

閱讀更多

準備好開始了嗎?

NuGet 下載次數 25,383版本:2026.11剛剛發布