public MobipocketDocument(MobipocketEncoding encoding, MobipocketCompression compression) { //create new pdb this._pdb = new PalmDatabaseFormat(); //create new header this.Header = new MobipocketHeader(); //set default properties this.Compression = compression; this.Encoding = encoding; }
private MobipocketDocument(PalmDatabaseFormat pdb) { if (pdb == null) { throw new ArgumentNullException("pdb"); } if (pdb.Records.Count < 1) { throw new Exception("palm database must contain at least one record"); } //set pdb this._pdb = pdb; //parse header this.Header = MobipocketHeader.FromPalmDatabase(_pdb); //parse records _records.AddRange(ParseMobipocketRecords()); }
/// <summary> /// Crates new instance of mobipocket header from provided palm database. /// </summary> /// <param name="pdb"></param> /// <returns></returns> internal static MobipocketHeader FromPalmDatabase(PalmDatabaseFormat pdb) { if (pdb == null) { throw new ArgumentNullException("pdb"); } if (pdb.Records.Count < 1) { throw new ArgumentException("no records in palm database"); } var bytes = pdb.Records.First().Data; if (bytes == null) { throw new ArgumentException("first record in palm database is malformed"); } return(FromBinary(new ArraySegment <byte>(bytes, 0, bytes.Length))); }
//--------------------------------------------- // // Static constructors // //--------------------------------------------- #region Static constructors /// <summary> /// Reads file into mobipocket document object /// </summary> /// <param name="path"></param> /// <returns></returns> public static MobipocketDocument FromFile(string path) { if (path == null) { throw new ArgumentNullException("path"); } try { using (var file = File.Open(path, FileMode.Open, FileAccess.Read)) using (BinaryReader reader = new BinaryReader(file)) { // read pdb format file var db = PalmDatabaseFormat.FromBinary(reader); //create the document from pdb return(new MobipocketDocument(db)); } } catch (Exception e) { throw new DocumentConstructionException("Cannot load mobipocket document from file", e); } }