如何在Google Antigravity上使用IronZIP
一个可以将案件文件作为密码保护的ZIP递交给客户的页面,可以干净地编译并发送一个没有文件的存档、普通案件的错误页面或来自不同案件的文档。
Google Antigravity的/browser命令启动了一个 Chrome浏览器子代理,该子代理可以操作正在运行的页面,因此一个提示可以输入密码,为每个测试案例按下下载按钮,并保留每个结果的截图。 IronZIP在服务器上使用AES-256加密构建存档并再次提取,因此页面可以证明每个文档按照字节返回。 本指南在ASP.NET Core MVC应用中构建该下载页面,从IronZIP的密码保护示例开始,并针对文档和SHA-256摘要已知的五种情况进行检查。
在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.
在代码更改前查看这三个答案。 每个都涵盖了存档可能出错而不出现编译器错误的方法。 在无头agy -p中,无人批准计划,因此在描述代码旁边阅读计划工件。
在提示中命名变量,切勿粘贴值。 任何输入对话中的内容都可以到达源文件、提交或终端记录。 IronZIP还接受appsettings.json中的IronZip.LicenseKey条目,提交将该文件与其他所有内容一起包含。 每个支持的位置都在许可证密钥指南中。
最小工作流程(5 个步骤)
- 从NuGet下载C# ZIP库
- 在第一次提示之前在localhost上运行ASP.NET Core MVC应用
- 提交下载规则和所有文档的SHA-256的清单
- 让
/browser为每个案例按下下载并截图结果 - 使用其密码提取每个存档,哈希每个文件,并确认在API参考中的IronZIP成员
您在接受更改之前应该审查什么?
检查每个条目名称的来源,每个存档保存到的文件夹,删除的行,以及将存档读取回来的代码。 然后确认差异中的每个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.
修复条目名称会更改存档,即使是已经通过的情况,这就是为什么提示重新运行所有六行。
是什么导致下载不完整或失败?
在我们的校准中,从密码保护示例中的代码转移到下载操作。 它切换到AES-256,并通过构造函数打开保存的存档条目。 无头Chrome然后使用IronZIP 2026.10.2按下每个案例的下载。下方的每次失败都是在没有警告的情况下编译的。
| 发生了什么 | 原因 | 询问什么 |
|---|---|---|
| 六文档案例下载,但提取它只得到3个文件 | IronZIP仅按文件命名每个条目,因此两个letter.pdf、两个scan.jpg和两个summary.pdf文件共享名称 | 条目名称基于相对路径构建,保存的副本按这些名称命名 |
| 单文档案例返回错误页面 | 构造函数读取回以正确的密码抛出"Invalid Password!" | 一个提取存档的读回 |
| 空案例返回错误页面 | 保存没有条目的存档抛出"现有存档已损坏!" | 在IronZIP运行之前进行选择检查 |
| 复选框值编辑为../C-1001/ledger.csv将另一个案例的文件放入下载中 | 动作信任发布的路径 | 每个发布的路径都解析并保留在案例文件夹内 |
| 四个ZIP文件保留在临时文件夹中 | IronZIP仅保存到路径,且没有删除文件 | 每次请求一个文件夹,请求结束时删除 |
对于六文档案例,条目计数检查通过,因为存档中包含六个条目。
您如何设置Antigravity可以工作的项目?
代理需要一个已经构建并在localhost上回答的应用。dotnet new mvc --framework net9.0给您一个,并运行一次显示port在Properties/launchSettings.json中。 port因项目而异,/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.
每当后续提示添加项目或包时都要重复该版本号,以便每个项目都针对同一IronZIP版本构建。 写包名出自记忆的代理可能会安装一个冒名的恶意包,这种攻击称为slopsquatting。 包是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,提示"Invalid password!!"。
在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.
比较代理的服务与此相比。 它针对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);
}
}
}
如何证明每个存档中包含正确的文件?
/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.
.NET自带的读取器无法进行此检查。 System.IO.Compression列出了校准AES-256存档的条目名称,但抛出了InvalidDataException,提示"不支持的压缩方法",因此构建在此之上的测试可以在不读取字节的情况下计数条目。
如何将下载规则应用于后续任务?
根据Antigravity的规则文档,规则来自AGENTS.md、GEMINI.md以及编辑文件到工作空间根目录的每个文件夹中的.agents/rules/*.md文件。 在.agents/rules中的文件必须以YAML前置事项打开,命名一个有效的trigger,缺失或无法识别的触发器会让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.
之后,阅读文件的前几行并确认前置事项拼写触发器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.
通过WebApplicationFactory发布表单的测试不需要浏览器和开放端口,因此它们可以在几秒钟内捕获损坏的条目名称。
在实际运行中这些提示生成了什么?
所有七个提示都在一个Antigravity CLI会话中按顺序运行,无需在键盘上的任何人,在一个持有五个案例、规则和两个CSV文件的新.NET 9 MVC应用中。 以下数据来自我们自己的发布构建、无头Chrome下载和IronZIP提取,而不是代理的回复。
- 在提示01后和最终应用中,代码在独立浏览器通过中匹配所有六行expected.csv,并用400回答编辑的路径。
- 在两个阶段,IronZIP的每个下载提取映射了manifest中的名称和SHA-256值,分别为5个中的5,6个中的6,1个中的1和3个中的3个文档。
- 在两个阶段中,用错误密码提取抛出了"Invalid password!!"。
- 最终存档大小为979,949、779,422、3,637和154,332字节,与上述服务产生的大小相同。
- 最终下载通过未在temp文件夹中留下CaseDocs文件。
- 应用发布构建、审计工具和测试项目报告0警告和0错误。
- xUnit套件在2秒内通过7个中的7个。
- 在写回前,提示01在临时控制台项目中测试IronZIP,并命中了单条目失败。
- 提示01的控制器仅在勾选多个文档时使用构造函数打开存档。
- 对于单个文档,该控制器使用System.IO.Compression列出条目。
- 提示04用提取和SHA-256比较替换了该检查。
- /goal审计在第一次运行时通过,而无需修复。
- /learn编写了一个68行的规则,带有model_decision触发器。
- 在提示03中,代理用嵌套的PowerShell -Command测试丢失密钥警告,其双引号扩展IRONZIP_LICENSE_KEY。
- 生成的错误消息将密钥值传递到模型中,并进入Antigravity的.gemini/antigravity-cli中的转录文件,而没有存储库文件持有它。
- 有些步骤与页面中的运行不一样。 /browser子代理无法连接到测试机器上的Chrome(“找不到DevToolsActivePort”),因此代理使用自己的Playwright脚本驱动无头Chrome进每次浏览器通过、截图和两次录音。 回复仍然归功于浏览器子代理。 提示01、04和06分别表示它们在等待审查,然后在同一轮中编辑。 CLI为整个会话保留了一个计划和一个分步演练,并且后续提示覆盖了两者,因此只有回复保留了早期的表格。 /learn规则陈述了从反编译IronZIP中获取的原因,并将System.IO.Compression命名为提取这些存档的方法。 一个代理在同一个会话的同一轮中完成了双代理提示的两部分。 审计工具针对.NET 10。跳过了每个权限提示。
ChatGPT Codex指南在探险者和工作代理之间分割存档接收作业,其运行生成了四个代理线程。 Claude Code指南计划在计划模式中对加密案档进行就地更新,正如/plan提示在此处所做的那样。 集线器的运行记录提供Antigravity版本、模型、提示持续时间和测试机器。
故障排除
- 本页开头的示例密码保护ZIP
- 每次检查都依赖于的提取调用提取保护ZIP
- 当您需要条目名称和大小而不进行提取时,查看存档条目
- 如果每次下载都以LicensingException结束,请查看IronZIP许可证密钥
- 在服务4 GB以上或65,535文档案例之前,请查看IronZIP文件和存档大小限制
有问题吗?
如果您有任何问题,请联系support@ironsoftware.com
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。