Skip to content

async lzma#1003

Merged
adamhathcock merged 15 commits intomasterfrom
adam/async-lzma
Nov 1, 2025
Merged

async lzma#1003
adamhathcock merged 15 commits intomasterfrom
adam/async-lzma

Conversation

@adamhathcock
Copy link
Owner

Related to #992

This pull request adds asynchronous read and write support to several LZMA-related stream classes, enhancing their compatibility with modern .NET patterns and improving performance in I/O-bound scenarios. The changes include implementing ReadAsync and WriteAsync methods, handling cancellation tokens, and updating internal logic to support async operations across the codebase.

Async I/O Support Across Stream Classes

  • Implemented ReadAsync and WriteAsync methods in LzmaStream, including an async version of DecodeChunkHeader to support asynchronous chunk decoding and data reading. [1] [2]
  • Added ReadAsync and WriteAsync methods to LZipStream, supporting both Memory<byte> and byte[] overloads for async operations, and delegated async calls to the underlying stream. [1] [2]
  • Provided async read support in AesDecoderStream by implementing ReadAsync with proper buffer management and cancellation handling.

Async Write Support in Utility Streams

  • Added WriteAsync to CrcBuilderStream, updating CRC asynchronously and supporting cancellation tokens.
  • Implemented WriteAsync in CrcCheckStream, allowing asynchronous CRC checking during write operations.

Async Compatibility in Decoder Streams

  • Implemented ReadAsync in Bcj2DecoderStream, wrapping the synchronous Read method for compatibility with async APIs and cancellation tokens.

These updates ensure that all major LZMA stream classes in the codebase now support asynchronous I/O, making them suitable for modern, high-performance applications that require non-blocking operations.

Copilot AI review requested due to automatic review settings October 30, 2025 16:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds async/await support to LZMA compression streams, enabling asynchronous I/O operations for better performance in async contexts.

  • Implements ReadAsync and WriteAsync methods for LZMA-related stream classes
  • Adds a new DecodeChunkHeaderAsync method in LzmaStream to support asynchronous chunk header reading
  • Ensures proper cancellation token handling throughout the async operations

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
CrcCheckStream.cs Adds WriteAsync override that delegates to synchronous Write method
CrcBuilderStream.cs Adds WriteAsync override that properly forwards async call to target stream
LzmaStream.cs Adds comprehensive async support with ReadAsync, WriteAsync, and DecodeChunkHeaderAsync implementations
LZipStream.cs Adds ReadAsync and WriteAsync overrides that delegate to underlying stream
Bcj2DecoderStream.cs Adds ReadAsync override that uses Task.FromResult to wrap synchronous operation
AesDecoderStream.cs Adds full ReadAsync implementation with proper async I/O operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings October 31, 2025 11:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings October 31, 2025 11:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings October 31, 2025 11:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

_inputPosition += await _outWindow
.CopyStreamAsync(_inputStream, toProcess, cancellationToken)
.ConfigureAwait(false);
}
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The synchronous _decoder.Code() method is being called within an async method without cancellation support. This could block the thread during async operations. Consider checking if the decoder operation can be made cancellable or document that this specific operation cannot be interrupted.

Suggested change
}
}
// The synchronous _decoder.Code() method is called here.
// This operation cannot be cancelled and may block the thread during async operations.

Copilot uses AI. Check for mistakes.
)
{
_outWindow.SetLimit(toProcess + 1);
if (!_decoder.Code(_dictionarySize, _outWindow, _rangeDecoder))
Copy link

Copilot AI Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The synchronous _decoder.Code() method is called within an async method without cancellation support. This could block the thread during async operations. Consider checking if the decoder operation can be made cancellable or document that this specific operation cannot be interrupted.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings November 1, 2025 10:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant