You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: AGENTS.md
+34-65Lines changed: 34 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,25 @@ applyTo: '**/*.cs'
6
6
# SharpCompress Development
7
7
8
8
## About SharpCompress
9
-
SharpCompress is a pure C# compression library supporting multiple archive formats (Zip, Tar, GZip, BZip2, 7Zip, Rar, LZip, XZ, ZStandard) for .NET Framework 4.62, .NET Standard 2.1, .NET 6.0, and .NET 8.0. The library provides both seekable Archive APIs and forward-only Reader/Writer APIs for streaming scenarios.
9
+
SharpCompress is a pure C# compression library supporting multiple archive formats (Zip, Tar, GZip, BZip2, 7Zip, Rar, LZip, XZ, ZStandard). The project currently targets .NET Framework 4.8, .NET Standard 2.0, .NET 8.0, and .NET 10.0. The library provides both seekable Archive APIs and forward-only Reader/Writer APIs for streaming scenarios.
10
10
11
11
## C# Instructions
12
-
-Always use the latest version C#, currently C# 13 features.
13
-
-Write clear and concise comments for each function.
12
+
-Use language features supported by the current project toolchain (`LangVersion=latest`) and existing codebase patterns.
13
+
-Add comments for non-obvious logic and important design decisions; avoid redundant comments.
14
14
- Follow the existing code style and patterns in the codebase.
15
15
16
16
## General Instructions
17
-
-**Agents should NEVER commit to git** - Agents should stage files and leave committing to the user. Only create commits when the user explicitly requests them.
17
+
-**Do not commit or stage changes unless the userexplicitly asks for it.**
18
18
- Make only high confidence suggestions when reviewing code changes.
19
19
- Write code with good maintainability practices, including comments on why certain design decisions were made.
20
20
- Handle edge cases and write clear exception handling.
21
21
- For libraries or external dependencies, mention their usage and purpose in comments.
22
22
- Preserve backward compatibility when making changes to public APIs.
23
23
24
+
### Workspace Hygiene
25
+
- Do not edit generated or machine-local files unless required for the task (for example: `bin/`, `obj/`, `*.csproj.user`).
26
+
- Avoid broad formatting-only diffs in unrelated files.
27
+
24
28
## Naming Conventions
25
29
26
30
- Follow PascalCase for component names, method names, and public members.
@@ -64,7 +68,7 @@ SharpCompress is a pure C# compression library supporting multiple archive forma
64
68
65
69
## Project Setup and Structure
66
70
67
-
- The project targets multiple frameworks: .NET Framework 4.62, .NET Standard 2.1, .NET 6.0, and .NET 8.0
71
+
- The project targets multiple frameworks: .NET Framework 4.8, .NET Standard 2.0, .NET 8.0, and .NET 10.0
68
72
- Main library is in `src/SharpCompress/`
69
73
- Tests are in `tests/SharpCompress.Test/`
70
74
- Performance tests are in `tests/SharpCompress.Performance/`
2.**Solid archives (Rar, 7Zip)** - Use `ExtractAllEntries()` for best performance, not individual entry extraction
179
203
3.**Stream disposal** - Always set `LeaveStreamOpen` explicitly when needed (default is to close)
180
204
4.**Tar + non-seekable stream** - Must provide file size or it will throw
181
-
6.**Format detection** - Use `ReaderFactory.Open()` for auto-detection, test with actual archive files
182
-
183
-
### Async Struct-Copy Bug in LZMA RangeCoder
184
-
185
-
When implementing async methods on mutable `struct` types (like `BitEncoder` and `BitDecoder` in the LZMA RangeCoder), be aware that the async state machine copies the struct when `await` is encountered. This means mutations to struct fields after the `await` point may not persist back to the original struct stored in arrays or fields.
awaitdecoder.Normalize2Async(cancellationToken).ConfigureAwait(false); // Struct gets copied here
198
-
return0; // Original _prob update may be lost
199
-
}
200
-
// ...
201
-
}
202
-
```
203
-
204
-
**The Fix:**
205
-
Refactor async methods on mutable structs to perform all struct mutations synchronously before any `await`, or use a helper method to separate the await from the struct mutation:
206
-
207
-
```csharp
208
-
// GOOD: struct mutations happen synchronously, await is conditional
In LZMA, the `BitEncoder` and `BitDecoder` structs maintain adaptive probability models in their `_prob` field. When these structs are stored in arrays (e.g., `_models[m]`), the async state machine copy breaks the adaptive model, causing incorrect bit decoding and eventually `DataErrorException` exceptions.
0 commit comments