public static FictionBook Deserialize(Stream stream) { FictionBook fb2book = null; XmlSerializer serializer = new XmlSerializer(typeof(FictionBook)); using (XmlReader reader = XmlReader.Create(stream)) { //StreamReader reader = new StreamReader(fs); fb2book = (FictionBook)serializer.Deserialize(reader); } return(fb2book); }
public static FictionBook ReadZipAsFB2(string zipPath) { FictionBook fb2book = null; using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { foreach (ZipArchiveEntry entry in archive.Entries) { if (entry.FullName.EndsWith(".fb2", StringComparison.OrdinalIgnoreCase)) { fb2book = FictionBook.Deserialize(entry.Open()); break; //entry.ExtractToFile(Path.Combine(extractPath, entry.FullName)); } } } return(fb2book); }
public static FictionBook Deserialize(string filename) { if (filename.EndsWith(".zip")) { return(FictionBookZipReader.ReadZipAsFB2(filename)); } FictionBook fb2book = null; XmlSerializer serializer = new XmlSerializer(typeof(FictionBook)); using (FileStream fs = new FileStream(filename, FileMode.Open)) { using (XmlReader reader = XmlReader.Create(fs)) { //StreamReader reader = new StreamReader(fs); fb2book = (FictionBook)serializer.Deserialize(reader); } } return(fb2book); }