From 4d8768ebeedb8cd2daa26dc935d66b0777aa5815 Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 18:17:33 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #51 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/IO/issues/51 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..d13ad42 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/IO/issues/51 +Your prepared branch: issue-51-14b9cbf4 +Your prepared working directory: /tmp/gh-issue-solver-1757776650456 + +Proceed. \ No newline at end of file From b58a04e6645df2a3f6d551a5aedf4ce2c5358994 Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 18:22:17 +0300 Subject: [PATCH 2/3] Fix OrDefault methods to return default values instead of throwing exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed GetValidFileStreamOrDefault to return null instead of throwing InvalidOperationException when file size is not aligned to element size. This ensures ReadFirstOrDefault and ReadLastOrDefault methods follow the OrDefault convention of returning default values in unexpected cases rather than throwing exceptions. Added comprehensive tests to verify the correct behavior for misaligned files. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- csharp/Platform.IO.Tests/FileHelpersTests.cs | 28 ++++++++++++++++++++ csharp/Platform.IO/FileHelpers.cs | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/csharp/Platform.IO.Tests/FileHelpersTests.cs b/csharp/Platform.IO.Tests/FileHelpersTests.cs index 3bdba03..88ab8df 100644 --- a/csharp/Platform.IO.Tests/FileHelpersTests.cs +++ b/csharp/Platform.IO.Tests/FileHelpersTests.cs @@ -15,5 +15,33 @@ public void WriteReadTest() Assert.Equal(readValue, originalValue); File.Delete(temporaryFile); } + + [Fact] + public void ReadFirstOrDefaultShouldReturnDefaultForMisalignedFile() + { + var temporaryFile = Path.GetTempFileName(); + // Write 5 bytes to create a file that's not aligned to ulong (8 bytes) + File.WriteAllBytes(temporaryFile, new byte[] { 1, 2, 3, 4, 5 }); + + // This should return default(ulong) = 0, not throw an exception + var result = FileHelpers.ReadFirstOrDefault(temporaryFile); + Assert.Equal(0UL, result); + + File.Delete(temporaryFile); + } + + [Fact] + public void ReadLastOrDefaultShouldReturnDefaultForMisalignedFile() + { + var temporaryFile = Path.GetTempFileName(); + // Write 5 bytes to create a file that's not aligned to ulong (8 bytes) + File.WriteAllBytes(temporaryFile, new byte[] { 1, 2, 3, 4, 5 }); + + // This should return default(ulong) = 0, not throw an exception + var result = FileHelpers.ReadLastOrDefault(temporaryFile); + Assert.Equal(0UL, result); + + File.Delete(temporaryFile); + } } } diff --git a/csharp/Platform.IO/FileHelpers.cs b/csharp/Platform.IO/FileHelpers.cs index fd412a3..00c65dd 100644 --- a/csharp/Platform.IO/FileHelpers.cs +++ b/csharp/Platform.IO/FileHelpers.cs @@ -85,7 +85,7 @@ private static FileStream GetValidFileStreamOrDefault(string path, int elementSi var fileSize = GetSize(path); if (fileSize % elementSize != 0) { - throw new InvalidOperationException($"File is not aligned to elements with size {elementSize}."); + return null; } return fileSize > 0 ? File.OpenRead(path) : null; } From ac8019db4a601420cf9d562bf5c41f1e2d94568c Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 18:22:56 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index d13ad42..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/IO/issues/51 -Your prepared branch: issue-51-14b9cbf4 -Your prepared working directory: /tmp/gh-issue-solver-1757776650456 - -Proceed. \ No newline at end of file