aboutsummaryrefslogtreecommitdiff
path: root/dotnet/Mammoth/Couscous/mammoth/internal/docx/ZippedDocxFile.cs
blob: cf39e63e6844c50e0e0c959660e966050d578012 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.IO.Compression;
using Mammoth.Couscous.java.io;
using Mammoth.Couscous.java.util;

namespace Mammoth.Couscous.org.zwobble.mammoth.@internal.docx {
    internal class ZippedDocxFile : DocxFile {
        private readonly ZipArchive _zipFile;
        
        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);
            if (entry == null) {
                return Optional.empty<InputStream>();
            } else {
                return Optional.of(ToJava.StreamToInputStream(entry.Open()));
            }
        }
        
        public void close() {
            _zipFile.Dispose();
        }
    }
}