aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-04-26 23:35:10 +0100
committerMichael Williamson <mike@zwobble.org>2016-04-26 23:35:10 +0100
commit5506c630f1974595a4fb23b0d7acdb163d96d807 (patch)
tree2ed30d080ae0c56b4307076998b826bee88d6a1d
parent29f0f5e881220626c5eb6a270ed73a653176660b (diff)
Implement InMemoryDocxFile
-rw-r--r--dotnet/Mammoth.Tests/DocumentConverterTests.cs9
-rw-r--r--dotnet/Mammoth/Couscous/mammoth/internal/docx/InMemoryDocxFile.cs14
-rw-r--r--dotnet/Mammoth/Couscous/mammoth/internal/docx/ZippedDocxFile.cs4
3 files changed, 18 insertions, 9 deletions
diff --git a/dotnet/Mammoth.Tests/DocumentConverterTests.cs b/dotnet/Mammoth.Tests/DocumentConverterTests.cs
index d94cb2d..5aec793 100644
--- a/dotnet/Mammoth.Tests/DocumentConverterTests.cs
+++ b/dotnet/Mammoth.Tests/DocumentConverterTests.cs
@@ -68,6 +68,15 @@ namespace Mammoth.Tests {
"Apple\n\nBanana\n\n");
}
+ [Fact]
+ public void CanExtractRawTextFromStream() {
+ using (var file = File.OpenRead(TestFilePath("simple-list.docx"))) {
+ assertSuccessfulConversion(
+ new DocumentConverter().ExtractRawText(file),
+ "Apple\n\nBanana\n\n");
+ }
+ }
+
private void assertSuccessfulConversion(IResult<string> result, string expectedValue) {
if (result.Warnings.Count > 0) {
throw new XunitException("Unexpected warnings: " + string.Join(", ", result.Warnings));
diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/docx/InMemoryDocxFile.cs b/dotnet/Mammoth/Couscous/mammoth/internal/docx/InMemoryDocxFile.cs
index a475acd..9b7efd0 100644
--- a/dotnet/Mammoth/Couscous/mammoth/internal/docx/InMemoryDocxFile.cs
+++ b/dotnet/Mammoth/Couscous/mammoth/internal/docx/InMemoryDocxFile.cs
@@ -1,17 +1,13 @@
using Mammoth.Couscous.java.io;
using Mammoth.Couscous.java.util;
+using System.IO;
namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.docx {
- internal class InMemoryDocxFile : DocxFile {
+ internal class InMemoryDocxFile {
internal static DocxFile fromStream(InputStream stream) {
- return new InMemoryDocxFile();
- }
-
- public Optional<InputStream> tryGetInputStream(string name) {
- throw new System.NotImplementedException();
- }
-
- public void close() {
+ var memoryStream = new MemoryStream();
+ stream.Stream.CopyTo(memoryStream);
+ return new ZippedDocxFile(memoryStream);
}
}
}
diff --git a/dotnet/Mammoth/Couscous/mammoth/internal/docx/ZippedDocxFile.cs b/dotnet/Mammoth/Couscous/mammoth/internal/docx/ZippedDocxFile.cs
index cad7a2f..cf39e63 100644
--- a/dotnet/Mammoth/Couscous/mammoth/internal/docx/ZippedDocxFile.cs
+++ b/dotnet/Mammoth/Couscous/mammoth/internal/docx/ZippedDocxFile.cs
@@ -9,6 +9,10 @@ namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.docx {
internal ZippedDocxFile(File file) {
_zipFile = ZipFile.OpenRead(file.Path);
}
+
+ internal ZippedDocxFile(System.IO.Stream stream) {
+ _zipFile = new ZipArchive(stream);
+ }
public Optional<InputStream> tryGetInputStream(string name) {
var entry = _zipFile.GetEntry(name);