Add Compression best practices guide#52968
Add Compression best practices guide#52968alinpahontu2912 wants to merge 6 commits intodotnet:mainfrom
Conversation
rzikm
left a comment
There was a problem hiding this comment.
It's getting better, few additional comments.
|
|
||
| ## Data integrity | ||
|
|
||
| ZIP entries include a CRC-32 checksum that you can use to verify data hasn't been corrupted or tampered with. |
There was a problem hiding this comment.
I think you should also mention TAR CRC in the first paragraph, now users might assume that this section is Zip-only and skip the rest of it.
There was a problem hiding this comment.
Pull request overview
Adds a new guidance article under File and stream I/O that explains how to work with ZIP and TAR archives in .NET, with a focus on API selection, safe extraction patterns, and operational considerations.
Changes:
- Adds a new best-practices article for ZIP and TAR archives, including security guidance for untrusted input.
- Adds a new C# snippet project and a consolidated
Program.cscontaining the referenced code regions. - Links the new article from
docs/fundamentals/toc.yml.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| docs/standard/io/zip-tar-best-practices.md | New best-practices guide covering API choice, trusted vs. untrusted extraction, memory/perf, platform differences, and encryption notes. |
| docs/standard/io/snippets/zip-tar-best-practices/csharp/Project.csproj | New snippet project targeting net11.0 for compiling the article snippets. |
| docs/standard/io/snippets/zip-tar-best-practices/csharp/Program.cs | Adds the C# snippet implementations referenced by the article. |
| docs/fundamentals/toc.yml | Adds a TOC entry pointing to the new best-practices article. |
| string destPath = Path.Join(destDir, entry.Name); | ||
| using var fileStream = File.Create(destPath); | ||
| entry.DataStream.CopyTo(fileStream); |
There was a problem hiding this comment.
TarStreamingRead writes entries directly to Path.Join(destDir, entry.Name) without creating parent directories. For common TAR entries with nested paths, File.Create(destPath) will throw because the directory doesn’t exist. Consider creating the parent directory first (and, if the sample might be used with untrusted input, also reuse the path validation approach shown earlier in the article).
|
cc also @GrabYourPitchforks and @blowdart for wording |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| // uncompressed size. In modern .NET, entry.Open() won't produce more | ||
| // than entry.Length bytes, so checking the declared size matches the | ||
| // runtime behavior that this sample relies on. |
There was a problem hiding this comment.
so checking the declared size matches the runtime behavior that this sample relies on.
This sentence reads weird, I would remove it
Summary
Add a guide explaining how to best work with Zip and Tar archives in .NET.
Internal previews