diff --git a/Source/VersOne.Epub.Test/Unit/Content/Loaders/EpubLocalContentLoaderTests.cs b/Source/VersOne.Epub.Test/Unit/Content/Loaders/EpubLocalContentLoaderTests.cs index 88d425d..33634c8 100644 --- a/Source/VersOne.Epub.Test/Unit/Content/Loaders/EpubLocalContentLoaderTests.cs +++ b/Source/VersOne.Epub.Test/Unit/Content/Loaders/EpubLocalContentLoaderTests.cs @@ -1,4 +1,5 @@ using System.Text; +using VersOne.Epub.Environment; using VersOne.Epub.Internal; using VersOne.Epub.Options; using VersOne.Epub.Test.Unit.Mocks; @@ -462,11 +463,15 @@ public void LoadContentWithMissingFileAndSuppressExceptionTrueTest() public void LoadContentWithMissingFileAndReplacementContentStreamSetTest() { ContentReaderOptions contentReaderOptions = new(); - contentReaderOptions.ContentFileMissing += (sender, e) => e.ReplacementContentStream = new MemoryStream(Encoding.UTF8.GetBytes(TEXT_FILE_CONTENT)); + byte[] replacementFileContent = Encoding.UTF8.GetBytes(TEXT_FILE_CONTENT); + contentReaderOptions.ContentFileMissing += (sender, e) => e.ReplacementContentStream = new MemoryStream(replacementFileContent); TestZipFile testZipFile = new(); EpubLocalContentLoader epubLocalContentLoader = CreateEpubLocalContentLoader(testZipFile, contentReaderOptions); string textContent = epubLocalContentLoader.LoadContentAsText(TextFileRefMetadata); Assert.Equal(TEXT_FILE_CONTENT, textContent); + IZipFileEntry replacementFileContentEntry = epubLocalContentLoader.GetContentFileEntry(TextFileRefMetadata); + Assert.Equal(replacementFileContent.Length, replacementFileContentEntry.Length); + Assert.Equal(replacementFileContent.Length, replacementFileContentEntry.CompressedLength); } [Fact(DisplayName = "Using replacement content multiple times while loading the same content file should succeed")] diff --git a/Source/VersOne.Epub.Test/Unit/Mocks/Test4GbZipFileEntry.cs b/Source/VersOne.Epub.Test/Unit/Mocks/Test4GbZipFileEntry.cs index 04cf6c9..30c0c1a 100644 --- a/Source/VersOne.Epub.Test/Unit/Mocks/Test4GbZipFileEntry.cs +++ b/Source/VersOne.Epub.Test/Unit/Mocks/Test4GbZipFileEntry.cs @@ -4,7 +4,11 @@ namespace VersOne.Epub.Test.Unit.Mocks { internal class Test4GbZipFileEntry : IZipFileEntry { - public long Length => (long)4 * 1024 * 1024 * 1024; + private const long SIZE_4GB = (long)4 * 1024 * 1024 * 1024; + + public long Length => SIZE_4GB; + + public long CompressedLength => SIZE_4GB; public Stream Open() { diff --git a/Source/VersOne.Epub.Test/Unit/Mocks/TestZipFileEntry.cs b/Source/VersOne.Epub.Test/Unit/Mocks/TestZipFileEntry.cs index 164ffec..6632458 100644 --- a/Source/VersOne.Epub.Test/Unit/Mocks/TestZipFileEntry.cs +++ b/Source/VersOne.Epub.Test/Unit/Mocks/TestZipFileEntry.cs @@ -45,6 +45,8 @@ public long Length } } + public long CompressedLength => Length; + public Stream Open() { if (memoryStream != null) diff --git a/Source/VersOne.Epub/Content/Loaders/EpubLocalContentLoader.cs b/Source/VersOne.Epub/Content/Loaders/EpubLocalContentLoader.cs index 95acd52..0780840 100644 --- a/Source/VersOne.Epub/Content/Loaders/EpubLocalContentLoader.cs +++ b/Source/VersOne.Epub/Content/Loaders/EpubLocalContentLoader.cs @@ -47,7 +47,7 @@ public override Task GetContentStreamAsync(EpubContentFileRefMetadata co return Task.FromResult(GetContentFileEntry(contentFileRefMetadata).Open()); } - private IZipFileEntry GetContentFileEntry(EpubContentFileRefMetadata contentFileRefMetadata) + public IZipFileEntry GetContentFileEntry(EpubContentFileRefMetadata contentFileRefMetadata) { if (replacementContentFileEntries.TryGetValue(contentFileRefMetadata.Key, out ReplacementContentFileEntry? existingReplacementContentFileEntry)) { diff --git a/Source/VersOne.Epub/Content/Loaders/ReplacementContentFileEntry.cs b/Source/VersOne.Epub/Content/Loaders/ReplacementContentFileEntry.cs index 8e6ae4c..f8063aa 100644 --- a/Source/VersOne.Epub/Content/Loaders/ReplacementContentFileEntry.cs +++ b/Source/VersOne.Epub/Content/Loaders/ReplacementContentFileEntry.cs @@ -19,6 +19,8 @@ public ReplacementContentFileEntry(Stream replacementStream) public long Length => replacementStreamContent.Length; + public long CompressedLength => replacementStreamContent.Length; + public Stream Open() { return new MemoryStream(replacementStreamContent); diff --git a/Source/VersOne.Epub/Environment/IZipFileEntry.cs b/Source/VersOne.Epub/Environment/IZipFileEntry.cs index dc275ab..0224f36 100644 --- a/Source/VersOne.Epub/Environment/IZipFileEntry.cs +++ b/Source/VersOne.Epub/Environment/IZipFileEntry.cs @@ -12,6 +12,11 @@ public interface IZipFileEntry /// long Length { get; } + /// + /// Gets the compressed size of the entry in the ZIP archive. + /// + long CompressedLength { get; } + /// /// Opens the entry from the ZIP archive. /// diff --git a/Source/VersOne.Epub/Environment/Implementation/ZipFileEntry.cs b/Source/VersOne.Epub/Environment/Implementation/ZipFileEntry.cs index 3ce4dd9..bc305ac 100644 --- a/Source/VersOne.Epub/Environment/Implementation/ZipFileEntry.cs +++ b/Source/VersOne.Epub/Environment/Implementation/ZipFileEntry.cs @@ -15,6 +15,8 @@ public ZipFileEntry(ZipArchiveEntry zipArchiveEntry) public long Length => zipArchiveEntry.Length; + public long CompressedLength => zipArchiveEntry.CompressedLength; + public Stream Open() { return zipArchiveEntry.Open();