Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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")]
Expand Down
6 changes: 5 additions & 1 deletion Source/VersOne.Epub.Test/Unit/Mocks/Test4GbZipFileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions Source/VersOne.Epub.Test/Unit/Mocks/TestZipFileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public long Length
}
}

public long CompressedLength => Length;

public Stream Open()
{
if (memoryStream != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override Task<Stream> 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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Source/VersOne.Epub/Environment/IZipFileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public interface IZipFileEntry
/// </summary>
long Length { get; }

/// <summary>
/// Gets the compressed size of the entry in the ZIP archive.
/// </summary>
long CompressedLength { get; }

/// <summary>
/// Opens the entry from the ZIP archive.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public ZipFileEntry(ZipArchiveEntry zipArchiveEntry)

public long Length => zipArchiveEntry.Length;

public long CompressedLength => zipArchiveEntry.CompressedLength;

public Stream Open()
{
return zipArchiveEntry.Open();
Expand Down
Loading