Skip to content

Refactor ReadResult decoding for Swift 6#735

Merged
mickael-menu merged 3 commits intodevelopfrom
fix/read-result-decoding
Feb 24, 2026
Merged

Refactor ReadResult decoding for Swift 6#735
mickael-menu merged 3 commits intodevelopfrom
fix/read-result-decoding

Conversation

@mickael-menu
Copy link
Member

Splits the Streamable.readAsX() async functions into an async read() and synchronous asX() functions. This is to avoid crossing isolation contexts with non sendable objects such as [String: Any].

Copy link

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 refactors the ReadResult decoding API for Swift 6 compatibility by splitting async reading from synchronous decoding operations. The refactoring addresses Swift 6's stricter concurrency requirements by avoiding crossing isolation contexts with non-Sendable types like [String: Any].

Changes:

  • Split Streamable.readAsX() async functions into separate read() (async) and asX() (synchronous) methods on ReadResult<Data> and ReadResult<Data?>
  • Made XML parsing methods synchronous (except for file I/O in open(file:) which uses Task.detached)
  • Added comprehensive tests for the new ReadResult decoding API using Swift Testing framework
  • Updated all call sites across the codebase to use the new read().asX() pattern
  • Deprecated the old readAsX() methods with migration guidance

Reviewed changes

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

Show a summary per file
File Description
Tests/SharedTests/Toolkit/Data/ReadResultTests.swift New comprehensive test suite for ReadResult decoding methods using Swift Testing framework
Tests/SharedTests/Publication/Services/Positions/PositionsServiceTests.swift Updated to use read().asString() pattern
Tests/SharedTests/Publication/PublicationTests.swift Updated to use read().asString() pattern
Sources/Streamer/Parser/Readium/ReadiumWebPubParser.swift Refactored to use read().asRWPM() pattern, moved extension from Streamable to ReadResult<Data>
Sources/Streamer/Parser/Readium/ReadiumGuidedNavigationService.swift Updated to use read().asJSONObject() pattern
Sources/Shared/Toolkit/XML/XML.swift Made open(data:) and open(string:) synchronous; open(file:) uses Task.detached for async I/O
Sources/Shared/Toolkit/Format/Sniffers/RPFFormatSniffer.swift Updated to use read().asJSONObject() pattern
Sources/Shared/Toolkit/Format/Sniffers/EPUBFormatSniffer.swift Updated to use read().asString() pattern and removed await from synchronous XML parsing
Sources/Shared/Toolkit/Format/FormatSnifferBlob.swift Removed await from synchronous XML parsing call
Sources/Shared/Toolkit/Data/Streamable.swift Deprecated readAsString(), readAsJSON(), and readAsJSONObject() with migration messages
Sources/Shared/Toolkit/Data/Resource/ResourceContentExtractor.swift Updated to use read().asString() and made XML parsing synchronous
Sources/Shared/Toolkit/Data/ReadResult.swift New file with decode(), asString(), asJSON(), asJSONObject(), and asXML() methods for both ReadResult<Data> and ReadResult<Data?>
Sources/Shared/Toolkit/Data/ReadError.swift Moved ReadResult typealias to ReadResult.swift
Sources/Shared/Publication/Services/Positions/PositionsService.swift Updated to use read().asJSONObject() pattern
Sources/Shared/Publication/Services/Content/Iterators/HTMLResourceContentIterator.swift Updated to use read().asString() pattern
Sources/LCP/Toolkit/ReadResult.swift Refactored readAsLCPL() from Streamable extension to asLCPL() on ReadResult<Data>

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

@mickael-menu mickael-menu merged commit bf4faf3 into develop Feb 24, 2026
5 checks passed
@mickael-menu mickael-menu deleted the fix/read-result-decoding branch February 24, 2026 18:01
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.

2 participants