예제 #1
0
        private static ManifestItem ReadFileContent(ZipStorer gz, XElement item, string opsFolder)
        {
            string       href = Helper.NullSaveString(item.Attribute(Helper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Href)), true);
            ManifestItem fi   = ManifestItem.Create(href);

            fi.Identifier   = Helper.NullSaveString(item.Attribute(Helper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Identifier)));
            fi.MediaOverLay = Helper.NullSaveString(item.Attribute(Helper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.MediaOverLay)));
            fi.Fallback     = Helper.NullSaveString(item.Attribute(Helper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Fallback)));
            fi.MediaType    = Helper.NullSaveString(item.Attribute(Helper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.MediaType)));
            using (MemoryStream ms = new MemoryStream()) {
                var entry = gz.ReadCentralDir().First(file => file.FilenameInZip == Helper.CreatePath(opsFolder, href));
                gz.ExtractFile(entry, ms);
                ms.Position = 0;
                fi.Data     = ms.ToArray();
            }
            fi.Properties = Helper.NullSaveString(item.Attribute(Helper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Properties)));
            return(fi);
        }
예제 #2
0
        private static ManifestItem ReadFileContent(ZipArchive gz, XElement item, string opsFolder)
        {
            string       href = item.Attribute(XmlHelper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Href)).NullSafeString(true);
            ManifestItem fi   = ManifestItem.Create(href);

            fi.Identifier   = item.Attribute(XmlHelper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Identifier)).NullSafeString();
            fi.MediaOverLay = item.Attribute(XmlHelper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.MediaOverLay)).NullSafeString();
            fi.Fallback     = item.Attribute(XmlHelper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Fallback)).NullSafeString();
            fi.MediaType    = item.Attribute(XmlHelper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.MediaType)).NullSafeString();
            var entry = gz.Entries.First(file => file.Name == opsFolder.CreatePath(href));

            using (var ms = entry.Open()) {
                ms.Position = 0;
                var buffer = new byte[(int)ms.Length];
                ms.Read(buffer, 0, buffer.Length);
                fi.Data = buffer;
            }
            fi.Properties = item.Attribute(XmlHelper.GetAttributeName <ManifestItem, EPubAttribute>(m => m.Properties)).NullSafeString();
            return(fi);
        }